Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upUnreachable expression in void-1.0.2, Rust 1.16 #38975
Comments
This comment has been minimized.
This comment has been minimized.
|
I think this is the same as #38977? |
This comment has been minimized.
This comment has been minimized.
|
That's intentionally caused by #38069 + |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
@brson yes, that was the idea. And yes, the example is surprising at first, but makes sense when you consider that a |
This comment has been minimized.
This comment has been minimized.
|
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>
.
|
This comment has been minimized.
This comment has been minimized.
|
Expected behavior. Please add this as a test case. |
brson
added
E-needstest
P-low
and removed
regression-from-stable-to-nightly
E-needstest
labels
Jan 12, 2017
This comment has been minimized.
This comment has been minimized.
|
@eddyb says we don't need this test. |
brson
closed this
Jan 12, 2017
This comment has been minimized.
This comment has been minimized.
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,
}
} |
brson commentedJan 10, 2017
•
edited
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