Skip to content

A pattern binding's view ends at its last use, as a let view's does: whole @ .Click(tag, n) => use(tag) + take(whole) is refused #3548

Closed

Description

@ehartford

§21.1, §9.7 (D230).

type Tag { name: str }
enum Ev:
    Click(tag: Tag, n: i32)

fn handle(e: Ev) -> i32:
    match move e:
        whole @ .Click(tag, n) => tag.name.len() as i32 + take(whole)
error: 'whole' is moved while 'tag' still views it

tag views whole and is last read before take(whole). A let k = tag.name.len() before the move does not help: the binding counts as viewing until the arm ends.

A view bound with let is already judged by its last use. This compiles and runs:

let v: List[Tok] = [Tok { id: 1 }, Tok { id: 2 }]
let x = v[0]      // a view of v
print(x.id)
let w = v         // accepted: x is not read again

So the gap is the pattern binding, not views in general: a name bound from a place by a pattern is held to its scope where a let view is held to its last use.

Expected. The two agree: a pattern binding that is not read after the move does not refuse it.

Workaround. Read what is needed in a match on a borrow of the value that ends before the move.

Activity

  1. changed the title [-]A view ends at its last use: `whole @ .Click(tag, n) => use(tag) + take(whole)` is refused though `tag` is never read after the move[/-] [+]A pattern binding's view ends at its last use, as a let view's does: `whole @ .Click(tag, n) => use(tag) + take(whole)` is refused[/+] on Nov 23, 2026
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