Skip to content

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

@5225225

Description

@5225225

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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