Skip to content

rustc suggests using enum type as variant #80607

Closed

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions