Skip to content

Allow by-move binding for patterns with guards that don't reference the bindings #14252

Closed
@kmcallister

Description

@kmcallister

I have

match token {
    DoctypeToken(dt) if mode == Initial => ...,
    DoctypeToken(dt) => ...,

    TagToken(x) => ...,
    CommentToken(x) => ...,
    // other cases

This gives

error: cannot bind by-move into a pattern guard

In this situation it should be fine to defer the move until the guard has succeeded.

It's a bit frivolous because I could instead do

match token {
    DoctypeToken(dt) => if mode == Initial {
        ...
    } else {
        ...
    },

    TagToken(x) => ...,
    CommentToken(x) => ...,
    // other cases

But I like having all the branching in one construct, especially when I'm implementing a spec which is written that way. And I don't want to add mode to the match scrutinee because none of the other cases care about it.

See also #4649.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions