Skip to content

Detect empty types in sub-patterns #36038

Closed
@canndrew

Description

@canndrew

If I define the following types

enum Three {
    A,
    B,
    C,
}

enum Two {
    A,
    B,
}

enum One {
    A,
}

enum Zero {
}

I can pattern match on them like this

match three {
    Three::A => (),
    Three::B => (),
    Three::C => (),
};

match two {
    Two::A => (),
    Two::B => (),
};

match one {
    One::A => (),
};

match zero {
};

But if I put them inside something (not just a tuple), I can no longer match the empty case

match (three,) {
    (Three::A,) => (),
    (Three::B,) => (),
    (Three::C,) => (),
}

match (two,) {
    (Two::A,) => (),
    (Two::B,) => (),
};

match (one,) {
    (One::A,) => (),
};

match (zero,) {    // ERROR!
};

This is inconsistent.

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