Skip to content

Incorrect path in E0004 match suggestion for enum from another module #137845

Closed
@makai410

Description

@makai410

Code

pub mod cat {
    pub enum Meow {
        Foo,
    }
}
fn main() {
    let v = cat::Meow::Foo;
    match v {}
}

Current output

error[E0004]: non-exhaustive patterns: `Meow::Foo` not covered
 --> src/main.rs:8:11
  |
8 |     match v {}
  |           ^ pattern `Meow::Foo` not covered
  |
note: `Meow` defined here
 --> src/main.rs:2:14
  |
2 |     pub enum Meow {
  |              ^^^^
3 |         Foo,
  |         --- not covered
  = note: the matched value is of type `Meow`
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 ~     match v {
9 +         Meow::Foo => todo!(),
10~     }
  |

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

Desired output

error[E0004]: non-exhaustive patterns: `Meow::Foo` not covered
 --> src/main.rs:8:11
  |
8 |     match v {}
  |           ^ pattern `Meow::Foo` not covered
  |
note: `Meow` defined here
 --> src/main.rs:2:14
  |
2 |     pub enum Meow {
  |              ^^^^
3 |         Foo,
  |         --- not covered
  = note: the matched value is of type `Meow`
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 ~     match v {
9 +         cat::Meow::Foo => todo!(),
10~     }
  |

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

I think there should be a discussion about whether the path should be in front of the name of the enum. Anyway, the code suggestion is wrong because it will cause an error if we apply it.

Other cases

Rust Version

playground(1.87.0-nightly (2025-02-28 287487624357c19b22d2))

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    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