-
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
Unreachable expression in void-1.0.2, Rust 1.16 #38975
Comments
I think this is the same as #38977? |
That's intentionally caused by #38069 + |
Woah! So I can now write:
That is, the match is not exhaustive over its variants! That seems very very surprising to me. It is tying this reachability analysis to the semantics of match in a new way that I would not expect. This type of match is an error on stable today. |
I guess, in some sense the new semantics only accept more code, so it's backwards compatible. As long as the lint is off you |
@brson yes, that was the idea. And yes, the example is surprising at first, but makes sense when you consider that a |
s/wrong/unsafe :)
…On Wed, Jan 11, 2017 at 3:03 PM, Niko Matsakis ***@***.***> wrote:
@brson <https://github.com/brson> yes, that was the idea. And yes, the
example is surprising at first, but makes sense when you consider that a
Void value can never exist in practice (or else you've done something
wrong)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#38975 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n3jeU94RMNpMtzECUdOsI3yXpvNUks5rRTWlgaJpZM4LgB57>
.
|
Expected behavior. Please add this as a test case. |
@eddyb says we don't need this test. |
It's consistent with how all other enums are handled: enum ThreeVariants {
V0,
V1,
V2,
}
enum TwoVariants {
V0,
V1,
}
enum OneVariant {
V0,
}
enum ZeroVariants {
}
fn unwrap_three(x: Result<u32, ThreeVariants>) -> u32 {
match x {
Ok(y) => y,
Err(ThreeVariants::V0) => 0,
Err(ThreeVariants::V1) => 1,
Err(ThreeVariants::V2) => 2,
}
}
fn unwrap_two(x: Result<u32, TwoVariants>) -> u32 {
match x {
Ok(y) => y,
Err(TwoVariants::V0) => 0,
Err(TwoVariants::V1) => 1,
}
}
fn unwrap_one(x: Result<u32, OneVariant>) -> u32 {
match x {
Ok(y) => y,
Err(OneVariant::V0) => 0,
}
}
fn unwrap_zero(x: Result<u32, ZeroVariants>) -> u32 {
match x {
Ok(y) => y,
}
} In other words, the fact that you can nest patterns and expand an n-variant enum in-place implies that you can elide empty enums like this (assuming we're being consistent). So you can still write this: fn unwrap_zero(x: Result<u32, ZeroVariants>) -> u32 {
match x {
Ok(y) => y,
Err(z) => match z {},
}
} But if you instead write it by expanding fn unwrap_zero(x: Result<u32, ZeroVariants>) -> u32 {
match x {
Ok(y) => y,
}
} |
https://github.com/reem/rust-void.git a6e061227f47ba8798b7e828ed0ac4e25382eb15
Not on stable/beta.
The code here is interesting. I don't quite see what the compiler does.
cc @reem
The text was updated successfully, but these errors were encountered: