Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Closed
ehuss opened this issue Sep 3, 2022 · 0 comments · Fixed by #101357
Closed

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

ehuss opened this issue Sep 3, 2022 · 0 comments · Fixed by #101357
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Sep 3, 2022

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)
@ehuss ehuss 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. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Sep 3, 2022
@compiler-errors compiler-errors self-assigned this Sep 3, 2022
@bors bors closed this as completed in d13aefd Sep 6, 2022
# for free to join this conversation on GitHub. Already have an account? # 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` 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