Skip to content

D115: a match guard after an owned-Vec slice pattern that removes elements is refused #2289

Closed

Description

@ehartford

Spec §9.7 (D115): [first, ..rest] over an owned Vec takes it apart by value in its own buffer: the tail elements come off the end, the head off the front (each by remove), and the remainder is the Vec itself.

A match arm runs its guard after its bindings, and a failed guard puts each moved binding back into the subject (restore_pattern_moves, which writes the value back to the place it came from). An element removed from a Vec came from no place: putting a tail element back is a push, a head element needs an insert at the front, and Vec has no insert (the stdlib's containers come from migrated corpora: STC, Phase 3). [..rest] alone removes nothing and is restored.

Until then Sema refuses the combination with an error naming this issue:

match make():
    [first, ..rest] if first.ok => ...

Expected: compiles; a failed guard leaves the subject whole for the next arm.
Fix: put removed elements back (push for the tail, a front insert for the head), or bind by view during the guard and move after it passes, as Rust does.

Activity

  1. changed the title [-]D115: a match guard after an owned-Vec slice pattern with head bindings is refused[/-] [+]D115: a match guard after an owned-Vec slice pattern that removes elements is refused[/+] on Oct 9, 2026
  2. ehartford commented on Oct 9, 2026

    @ehartford
    ContributorAuthor

    D115 Amendment 1 (#2292) gives an owned Vec remainder a start offset in the header; a failed guard then puts head elements back by moving the offset back and tail elements back into the capacity they left. This issue closes with that implementation.

  3. ehartford commented on Oct 12, 2026

    @ehartford
    ContributorAuthor

    Merged to main in c97a008 (#2352): a failed guard puts a head back through the prefix its O(1) take left (with_vec_restore_front_es) and a tail back by push, after the remainder is back in the subject; fixture behav_2289_guard_after_owned_list_take.w.

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