Suggestions when a single-field enum variant pattern is needed #94942
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Beginners are often confused by the pattern where a set of types are combined using an
enum
, especially when the name of the enum variant is the same as the name of the variant's field's type. Even knowing how it works, I've myself forgotten to write out enum variant patterns containing struct patterns where they are needed. It would be useful if the compiler could give suggestions that understand this mistake.Given the following code:
The current output is:
The compiler could instead recognize these cases, and produce the suggestion
Foo::Bar(Bar { x }) =>
as well as a message specific to the situation:@rustbot label +A-suggestion-diagnostics +C-enhancement +D-newcomer-roadblock
The text was updated successfully, but these errors were encountered: