Skip to content

E0004 non-exhaustive patterns suggestion has unqualified enum variant #101356

Closed

Description

Given the following code:

enum Foo {
    Variant1,
    Variant2,
}

fn main() {
    match Foo::Variant2 {
        Foo::Variant1 => {}
    }
}

The current output is:

    Checking foo v0.1.0 (/Users/eric/Temp/foo)
error[E0004]: non-exhaustive patterns: `Variant2` not covered
 --> src/main.rs:7:11
  |
7 |     match Foo::Variant2 {
  |           ^^^^^^^^^^^^^ pattern `Variant2` not covered
  |
note: `Foo` defined here
 --> src/main.rs:3:5
  |
1 | enum Foo {
  |      ---
2 |     Variant1,
3 |     Variant2,
  |     ^^^^^^^^ not covered
  = note: the matched value is of type `Foo`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
  |
8 ~         Foo::Variant1 => {}
9 +         Variant2 => todo!()
  |

For more information about this error, try `rustc --explain E0004`.
error: could not compile `foo` due to previous error

The problem with the suggestion is that it suggests Variant2 without the Foo:: prefix. Ideally the suggestion should be:

9 +         Foo::Variant2 => todo!()

The current suggestion does not compile.

rustc 1.65.0-nightly (9c20b2a8c 2022-08-17)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`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