Skip to content

Unhelpful message for syntax error in pattern bindings #72298

Closed
@benschulz

Description

@benschulz

When changing a pattern binding from something like

match some_value {
    SomeEnum::SomeVariant { ref some_field } => { /* do something with some_field */ },
    _ => {}
}

to something like

match some_value {
    SomeEnum::SomeVariant { some_field: ref alias } => { /* do something with alias */ },
    _ => {}
}

it's easy to end up with

match some_value {
    SomeEnum::SomeVariant { ref some_field: alias } => { /* do something with alias */ },
    _ => {}
}

which yields an unhelpful syntax error message (playground). I don't believe it's obvious why ref some_field and some_field: alias are valid, but ref some_field: alias is not. The same holds for ref mut bindings, of course.

It would be nice if rustc's parser accepted the invalid syntax and provided one of its helpful "did you mean to write some_field: ref alias?" error messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions