Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name of enum variant with fields is suggested in error messages #73427

Closed
Aaron1011 opened this issue Jun 17, 2020 · 3 comments · Fixed by #77341
Closed

Name of enum variant with fields is suggested in error messages #73427

Aaron1011 opened this issue Jun 17, 2020 · 3 comments · Fixed by #77341
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Jun 17, 2020

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.

@Aaron1011 Aaron1011 added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Jun 17, 2020
@estebank estebank added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Jun 17, 2020
@doctorn
Copy link
Contributor

doctorn commented Jun 19, 2020

@rustbot claim

@rustbot rustbot self-assigned this Jun 19, 2020
@Alexendoo
Copy link
Member

Triage: Hi, are you still working on this issue @doctorn?

@Alexendoo
Copy link
Member

@rustbot release-assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants