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
Exhaustiveness: a match on a slice or Vec whose slice patterns cover every length ([] / [_] / [_, ..]) still demands a '_' arm; the §9.7 example is rejected #1533
The patterns cover every length: 0, then 1, then 1 or more. The exhaustiveness engine (SemaCheck, the #1388 pattern matrix) classifies a dynamic slice as Open. The comment above SemaPatRows says so on purpose: "Every other type (str, floats, dynamic slices, ...) is open: only a catch-all covers it". So such a match is rejected:
fn head(s: []i32) -> i32:
match s:
[a, b] => a - b
[a, ..] => a
[] => -2
error: non-exhaustive match on '[]i32': `_` is not covered
(stage1 of the #1389 branch. #1389 makes slice patterns over slices and Vecs lower at all, and its fixture adds the _ arm because of this.)
Slice patterns only bind names (Parser.parse_slice_pattern accepts identifiers and one ..), so exhaustiveness over a slice or Vec reduces to length coverage. A rest pattern with k fixed elements covers every length >= k, and an exact pattern covers one length. The match is exhaustive exactly when each length from 0 up to the smallest rest minimum is covered. A SemaExhClass.Slice column with length constructors would give the witness too, for example "a slice of length 2 is not covered".
The spec example also uses a named rest over a dynamic sequence ({rest.len()} more), which is still reported as "slice rest binding for dynamic slices is not implemented yet". §9.7 binds rest to "the remaining count" for fixed-size arrays and uses it as a slice in this example, so which of the two a dynamic rest binds is a ruling. That is part of the #1389 report.
Spec self-conflict noted: §9.7 line 4244 says rest "is bound to the remaining count", while both examples (lines 1849, 4239) write rest.len(), which needs the remaining elements. Proposed to Eric: ..rest binds a view of the remaining elements (&[]T for a dynamic subject; D27: element access observes), and line 4244 is corrected. The rejected []/[_]/[_, ..] exhaustiveness is a compiler bug regardless. Pending Eric's yes.
Activity
Slice patterns over a Vec, a slice or a borrowed array bind element v…
ehartford commentedon Sep 23, 2026
Spec self-conflict noted: §9.7 line 4244 says
rest"is bound to the remaining count", while both examples (lines 1849, 4239) writerest.len(), which needs the remaining elements. Proposed to Eric:..restbinds a view of the remaining elements (&[]Tfor a dynamic subject; D27: element access observes), and line 4244 is corrected. The rejected[]/[_]/[_, ..]exhaustiveness is a compiler bug regardless. Pending Eric's yes.Slice patterns over a Vec, a slice or a borrowed array bind element v…