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

rustc suggests using enum type as variant #80607

Closed
camelid opened this issue Jan 2, 2021 · 1 comment · Fixed by #80613
Closed

rustc suggests using enum type as variant #80607

camelid opened this issue Jan 2, 2021 · 1 comment · Fixed by #80613
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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.

Comments

@camelid
Copy link
Member

camelid commented Jan 2, 2021

Both the error and the suggestion make it seem like Enum is an enum variant; it's a type, not a variant.

pub enum Enum {
    V1(i32),
}

pub fn foo(x: i32) -> Enum {
    Enum::V1 { x }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0559]: variant `Enum::V1` has no field named `x`
 --> src/lib.rs:6:16
  |
2 |     V1(i32),
  |     -- `Enum` defined here
...
6 |     Enum::V1 { x }
  |     --------   ^ field does not exist
  |     |
  |     `Enum` is a tuple variant, use the appropriate syntax: `Enum(/* fields */)`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0559`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

@camelid camelid added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` 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-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Jan 2, 2021
bugadani added a commit to bugadani/rust that referenced this issue Jan 2, 2021
@bugadani
Copy link
Contributor

bugadani commented Jan 2, 2021

@rustbot claim

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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants