-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Arms permitted when matching on uninhabited types #55123
Comments
The second issue is a direct result of the first, where "number of arms" is treated as a heuristic for divergence, rather than the type of the expression (this could be an issue in the future with regards to an explicit |
This is due to: rust/src/librustc_mir/hair/pattern/_match.rs Lines 374 to 380 in 0982be7
exhaustive_patterns .
|
I don't think |
Handle empty matches cleanly in exhaustiveness checking This removes the special-casing of empty matches that was done in `check_match`. This fixes most of rust-lang#55123. Somewhat unrelatedly, I also made `_match.rs` more self-contained, because I think it's cleaner. r? `@varkor` `@rustbot` modify labels: +A-exhaustiveness-checking
The second issue got fixed in #78995. I'm wondering about the first one: is matching on an empty enum very different from getting a value of an empty type as input? My hunch would be that if we lint any code after pub enum Void {}
pub fn foo(x: Void) {
let _ = (); // Frankly this also could be warned as unreachable.
match x {};
let _ = (); // This could be warned as unreachable, but isn't.
} |
I agree that these are essentially the same issue. I actually submitted a PR a couple of years ago to address this, by making the uninhabitedness checking more eager (see #47291), but parts of it were split out to err on the side of being more conservative. I can't quite remember the status: probably in order to make these changes, there would need to be a discussion into how eagerly one wants to mark unreachable code based on uninhabited types. Probably this issue can be closed, and potentially a new one opened to explore reachability based on inhabitedness. |
It looks like the pub enum Void {}
pub fn foo(x: Void) {
match x {
_ => {} // This arm shouldn't be permitted.
};
let _xyz = (); // This should be warned as unreachable, but isn't.
} |
Not sure if related, but I encountered two surprising error: enum Empty {}
fn foo(x: &Empty) {
match x {} // ERROR: missing match arm.
} enum Empty1 {}
enum Empty2 {}
fn foo(x: (Empty1, Empty2)) {
match x {} // ERROR: missing match arm.
} I have to add a |
There seem to be two issues here:
On the other hand, the following code does warn:
The text was updated successfully, but these errors were encountered: