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

Inner match doesn't narrow exhaustiveness scope based on outer binding #77542

Closed
HackAttack opened this issue Oct 4, 2020 · 1 comment
Closed

Comments

@HackAttack
Copy link
Contributor

It seems like the following should compile

enum Enum {
    A,
    B,
    C,
}

fn main() {
    match Enum::A {
        x @ Enum::A | x @ Enum::B => match x {
            Enum::A => println!("a"),
            Enum::B => println!("b"),
            // _ => unreachable!(),  // Won't compile without this line
        }
        Enum::C => println!("c"),
    }
}

because the inner match only executes on A and B. But exhaustiveness is checked over the whole enum even though only a subset of variants are possible in this context.

Maybe related: #8391

@jonas-schievink
Copy link
Contributor

Hi! This is currently working as intended, and changing this would be a language change. Additions or changes to the language need to go through our RFC process. Before an RFC is written, the feature can also be discussed in our internals forum to find other people interested in it.

Closing in favor of an RFC.

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

2 participants