reference
reference copied to clipboard
Add an example for when path patterns take precedence over identifier patterns
In the Identifier Patterns section it is mentioned that path patterns take precedence over identifier patterns.
I thought adding the following example would be helpful to demonstrate this:
fn main() {
const NUMBER: i32 = 10;
let a = 12;
match a
{
NUMBER => {assert_eq!(NUMBER, 10)}, //NUMBER here is 10, it does NOT shadow a
_ => () //this catch-all is needed or we would get a non-exhaustive patterns error
}
}
I was also wondering if this type of example is the only type there is: Are there any other types of examples where you would see this precedence taking place?