You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Slice pattern rest binding on a Vec or slice: refused as not implemented; spec says count for arrays but uses rest.len() #2283
match items:
[first, ..rest] => "head: {first}, {rest.len()} more"
and let [first, ..rest] = items else return Err(.Empty), but the rule text says that for fixed-size arrays rest is bound to the remaining count (the compiler binds an i64).
On a Vec or a slice the compiler refuses the binding: error: slice rest binding for dynamic slices is not implemented yet (src/SemaCheck.w, check_pattern NK_PAT_SLICE).
Repro:
fn main:
let v = [1, 2, 3] // a Vec (D113)
match v:
[first, ..rest] => print(first)
_ => print(0)
Expected: compiles; rest is what the spec's own example uses (rest.len()), presumably a []T view of the remaining elements.
Actual: refused.
D113 makes this common: before it, let arr = [1, 2, 3] was a fixed array and the count form applied. The behavior tests that exercised it (behav_slice_pattern_rest_binding, slice_pat_both, slice_pat_head_rest, slice_pat_exhaustive, behav_1367) now annotate [i32; N].
Two things are owed: the implementation, and a ruling on the array form. A rest that is a count for an array and a view for a Vec means the same source changes meaning with the demanded type; the uniform reading is a view in both.
Fixed by D115 phase 1 (#2297, merged 535711d). Spec §9.7 rules rest as the remaining elements (D115, #2288). Verified on the installed compiler at 58b1448: match v: [a, ..rest] over a List place prints 10 2 20, and let [first, ..rest] = s else ... over a slice returns 3. The O(1) owned-List remainder (D115 Amendment 1) is tracked with the List header change; the guard refusal is #2289.
Activity
D113: brackets make a Vec; a fixed array or set is built where demand…
D115: a slice pattern's rest names the remaining elements; subject ow…
D115: a slice pattern's rest names the remaining elements; subject ow…
ehartford commentedon Oct 9, 2026
Fixed by D115 phase 1 (#2297, merged 535711d). Spec §9.7 rules rest as the remaining elements (D115, #2288). Verified on the installed compiler at 58b1448:
match v: [a, ..rest]over a List place prints10 2 20, andlet [first, ..rest] = s else ...over a slice returns 3. The O(1) owned-List remainder (D115 Amendment 1) is tracked with the List header change; the guard refusal is #2289.