Open
Description
I tried this code:
#[repr(i32)]
pub enum Something {
Foo = 0,
Bar = 1,
Blarg = 2,
}
fn main() {
let my_int: i32 = 1;
match my_int {
1 => {}
//1 => {} // Warning: no value can reach this
x if x == Something::Foo as i32 => {}
x if x == Something::Foo as i32 => {} // No warning
x if x == Something::Foo as i32 => {} // No warning
x if x == Something::Blarg as i32 => {}
_ => {}
}
}
rustc
seems to happily accept multiple identical cases of enums as i32
in match statements. Using i32
directly gives warnings as expected, but not when representing the enum as i32
. There are no warnings in nightly nor in rustc 1.0.0
, tested on https://rust.godbolt.org/.
I would expect the same warning for the second x if x == Something::Foo as i32 => {}
as for the second 1 => {}
in the example below.
At the time of writing https://rust.godbolt.org/ does not allow me to see the disassembly for nightly
. But for 1.0.0
the same code is generated for each statement with different offsets.
rustc --version --verbose
:
nightly