-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Pattern matching on C-like enums when values are not imported cause unintuitive behaviour #10402
Comments
This would also be resolved by forcing local variables to be |
I'm not sure if this is the same issue, but when using a non existent identifier in a pattern match with a enum, all following matches are Here the example code: enum Greeting {
Hello,
ByeBye
}
fn main() {
let that = Hello;
match that {
Hello => (),
NonExistent => (),
ByeBye => ()
}
} And a pre-populated Rust Playground link: |
We now print a message like |
Thanks @eefriedman! |
Rustup Looks like `@flip1995` is busy. r? `@ghost` changelog: None
When doing pattern matching on a C-like enum whose values haven't be imported in the current namespace, like :
Rustc doesn't know Baz and Qux are values, since they are not imported.
The first Baz pattern is thus considered as a binding, and all following patterns are seen as "unreachable".
Maybe we should put the enum value names inside the namespace of the enum type (like C++11 enum classes), and, in any case, implement a better error or warning message. Many people apparently ran into this issue, and found it very weird and hard to debug. (cc @cmr )
The text was updated successfully, but these errors were encountered: