Skip to content

Missing match arms suggests the function name for enums defined inside the function but shadowed #137682

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

Open
5225225 opened this issue Feb 26, 2025 · 2 comments · May be fixed by #137783
Open
Assignees
Labels
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.

Comments

@5225225
Copy link
Contributor

5225225 commented Feb 26, 2025

Code

struct Shadowed {}

fn make_index() {
    let v = Shadowed::Foo;

    match v {}

    enum Shadowed {
        Foo,
    }
}

fn main() {}

Current output

Compiling playground v0.0.1 (/playground)
error[E0004]: non-exhaustive patterns: `make_index::Shadowed::Foo` not covered
 --> src/main.rs:6:11
  |
6 |     match v {}
  |           ^ pattern `make_index::Shadowed::Foo` not covered
  |
note: `make_index::Shadowed` defined here
 --> src/main.rs:8:10
  |
8 |     enum Shadowed {
  |          ^^^^^^^^
9 |         Foo,
  |         --- not covered
  = note: the matched value is of type `make_index::Shadowed`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
  |
6 ~     match v {
7 +         make_index::Shadowed::Foo => todo!(),
8 ~     }
  |

For more information about this error, try `rustc --explain E0004`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0004]: non-exhaustive patterns: `Shadowed::Foo` not covered
 --> src/main.rs:6:11
  |
6 |     match v {}
  |           ^ pattern `Shadowed::Foo` not covered
  |
note: `make_index::Shadowed` defined here
 --> src/main.rs:8:10
  |
8 |     enum Shadowed {
  |          ^^^^^^^^
9 |         Foo,
  |         --- not covered
  = note: the matched value is of type `Shadowed`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
  |
6 ~     match v {
7 +         Shadowed::Foo => todo!(),
8 ~     }
  |

For more information about this error, try `rustc --explain E0004`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Rationale and extra context

Unsure if make_index should be dropped from the name of the enum, but it definitely needs to be removed from the code suggestion, since it's not needed, and causes an error.

Other cases

Rust Version

1.87.0-nightly

(2025-02-25 85abb276361c424d6474)

(I'm testing this on the playground, and it happens for all of stable, beta, nightly there)

Anything else?

No response

@5225225 5225225 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. labels Feb 26, 2025
@makai410
Copy link
Contributor

@rustbot claim

@makai410
Copy link
Contributor

I guess only adjusting the code suggestion is better because make_index::Shadowed::Foo is more specific in this case.

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 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