Closed
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
Area: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.