-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Incorrect path in E0004 match suggestion for enum from another module #137845
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
Comments
This issue is not as simple as "missing path". There is some bugs on trimming the def path. Consider the examples below:Example 1 pub mod cat {
pub mod frog {
pub enum Meow {
Foo,
}
}
}
fn dog() {
enum Meow {
Foo,
}
}
fn main() {
let v = cat::frog::Meow::Foo;
match v {
}
} with its output: error[E0004]: non-exhaustive patterns: `frog::Meow::Foo` not covered
--> src/main.rs:15:11
|
15 | match v {
| ^ pattern `frog::Meow::Foo` not covered
|
note: `frog::Meow` defined here
--> src/main.rs:3:18
|
3 | pub enum Meow {
| ^^^^
4 | Foo,
| --- not covered
= note: the matched value is of type `frog::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
|
16 | match v {
17 ~ frog::Meow::Foo => todo!(),
18 ~ }
|
For more information about this error, try `rustc --explain E0004`.
error: could not compile `playground` (bin "playground") due to 1 previous error Example 2 pub mod cat {
pub mod cat {
pub enum Meow {
Foo,
}
}
}
fn dog() {
enum Meow {
Foo,
}
}
fn main() {
let v = cat::cat::Meow::Foo;
match v {
}
} with its output: error[E0004]: non-exhaustive patterns: `cat::cat::Meow::Foo` not covered
--> src/main.rs:15:11
|
15 | match v {
| ^ pattern `cat::cat::Meow::Foo` not covered
|
note: `cat::cat::Meow` defined here
--> src/main.rs:3:18
|
3 | pub enum Meow {
| ^^^^
4 | Foo,
| --- not covered
= note: the matched value is of type `cat::cat::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
|
16 | match v {
17 ~ cat::cat::Meow::Foo => todo!(),
18 ~ }
|
For more information about this error, try `rustc --explain E0004`.
error: could not compile `playground` (bin "playground") due to 1 previous error it seems to emit a right code suggestion, but if we remove the function
|
This issue corresponds to #137682 , actually reporting the same problem. |
Thanks for catching this! I will close this issue since it's by design. |
Code
Current output
Desired output
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
Anything else?
No response
The text was updated successfully, but these errors were encountered: