-
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 lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.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
The following code:
enum MyEnum {
First(bool),
Second
}
fn main() {
MyEnum.foo();
}
gives the following error message
error[E0423]: expected value, found enum `MyEnum`
--> src/main.rs:7:5
|
7 | MyEnum.foo();
| ^^^^^^
|
help: try using one of the enum's variants
|
7 | MyEnum::First.foo();
| ^^^^^^^^^^^^^
7 | MyEnum::Second.foo();
| ^^^^^^^^^^^^^^
MyEnum::First.foo()
calls foo
on a function pointer (the constuctor function for MyEnum::First
, which is almost never what you want.
At the very least, we should not be suggesting using enum variants that have associated data. When attempting to call a method on the base enum type, we might want to suggest using ::
instead (e.g. MyEnum::First::foo()
), which is more likely to be what the user wants.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.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.