Skip to content

Slice pattern over &Vec[T] passes Sema, then invalid MIR (match and let-else) #1389

Closed

Description

@ehartford

A slice pattern over a &Vec[T] subject is accepted by Sema and then fails MIR validation, in both match and let ... else (§9.7 slice destructuring, §30.6 SLICE_PAT). Arrays ([4]i32) work (test/behavior/behav_let_else_slice_rest_binding.w).

fn g(v: &Vec[i32]) -> i32:
    match v:
        [first, ..] => first
        _ => -1
fn main:
    var a: Vec[i32] = Vec.new()
    let b: Vec[i32] = Vec.new()
    a.push(4)
    print(f"{g(a)} {g(b)}")

Actual (stage1 of origin/fix-1354-var-destructure-mut a7e2004, same on the seed):

error: invalid MIR before codegen: use rvalue does not resolve to a concrete MIR type (place local=2 local_ty=941 projs=1 proj0_kind=0)
 --> slm.w:3:9
3 |         [first, ..] => first

Expected: 4 -1. let [first, ..] = v else: return -1 fails the same way. Either the pattern is lowered over the Vec's elements or Sema rejects it with a diagnostic; an invalid-MIR ICE is neither. Found while building the #1373/#1382 let-else matrix.

Activity

  1. ehartford commented on Sep 23, 2026

    @ehartford
    ContributorAuthor

    PR #1405 (#1388) makes MirLower's pattern-test default loud: a slice pattern over a subject that is not a fixed-size array now fails MIR lowering with "pattern kind 113 has no match-test lowering". Before, it fell into an accept-everything goto, so match s: [] => ..., [a] => ... over a []i32 silently took the first arm. The lowering itself is still this issue's job.

  2. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Verified fixed on main 55739d4 (release binary): slice pattern over &Vec[i32] runs, prints 4 -1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions