Skip to content
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

Add an example for when path patterns take precedence over identifier patterns #1462

Open
Tomer-Eliahu opened this issue Jan 31, 2024 · 0 comments

Comments

@Tomer-Eliahu
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant