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

Detect empty types in sub-patterns #36038

Closed
canndrew opened this issue Aug 27, 2016 · 2 comments
Closed

Detect empty types in sub-patterns #36038

canndrew opened this issue Aug 27, 2016 · 2 comments

Comments

@canndrew
Copy link
Contributor

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.

@canndrew canndrew changed the title Detect empty type in sub-patterns Detect empty types in sub-patterns Aug 27, 2016
@canndrew
Copy link
Contributor Author

The main reason I want this is because it will allow people to match on enums while eliding variants that have been "deleted" using !. For example, people should be allowed to match on Result<T, !> with

match result {
    Ok(x) => x,
}

Currently, they have to do

match result {
    Ok(x) => x,
    Err(e) => e,
}

Which is confusing because it looks like they're matching on a Result<T, T>.

@canndrew
Copy link
Contributor Author

Closing this as a dupe of #12609.

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