Skip to content

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

Closed
@HackAttack

Description

@HackAttack

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions