-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.