-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rules for matching against variable unclear. #28687
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
You can match against patterns that are composed of: Literals, ranges, Struct constructors, Enum variant constructors and If you put in an identifier like this it's just a new binding (a catch-all). Rust generally allows variable shadowing without warning ( |
Relevant doc section is Patterns. I think it could be clarified around this issue. |
tagging with docs to see if i can make this somehow more prominent, but I'm not sure. |
When you have a match statement against a variable the behaviour is unexpected.
I tried this code:
I expected to to see this happen:
Either get an error telling me that placing a variable won't do what I think it will do. Or allow this to happen, and allow for specific cases, as currently adding any extra arms returns a
unreachable pattern
error.Instead this happened:
This compiles with no errors, or warning, and prints out:
Meta
rustc --version --verbose
The text was updated successfully, but these errors were encountered: