2016-03-28 22:08:08 -05:00
|
|
|
enum Foo {
|
|
|
|
Bar = 42,
|
|
|
|
Baz,
|
|
|
|
Quux = 100,
|
|
|
|
}
|
|
|
|
|
2016-05-08 20:49:07 -05:00
|
|
|
enum Signed {
|
|
|
|
Bar = -42,
|
|
|
|
Baz,
|
|
|
|
Quux = 100,
|
|
|
|
}
|
|
|
|
|
2016-03-28 22:08:08 -05:00
|
|
|
fn foo() -> [u8; 3] {
|
2019-06-10 02:50:47 -05:00
|
|
|
let baz = Foo::Baz; // let-expansion changes the MIR significantly
|
|
|
|
[Foo::Bar as u8, baz as u8, Foo::Quux as u8]
|
2016-03-28 22:08:08 -05:00
|
|
|
}
|
|
|
|
|
2016-05-08 20:49:07 -05:00
|
|
|
fn signed() -> [i8; 3] {
|
2019-06-10 02:50:47 -05:00
|
|
|
let baz = Signed::Baz; // let-expansion changes the MIR significantly
|
|
|
|
[Signed::Bar as i8, baz as i8, Signed::Quux as i8]
|
2016-05-08 20:49:07 -05:00
|
|
|
}
|
|
|
|
|
2016-03-28 22:08:08 -05:00
|
|
|
fn unsafe_match() -> bool {
|
|
|
|
match unsafe { std::mem::transmute::<u8, Foo>(43) } {
|
|
|
|
Foo::Baz => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 03:34:14 -05:00
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
fn main() {
|
2016-05-09 22:53:20 -05:00
|
|
|
assert_eq!(foo(), [42, 43, 100]);
|
|
|
|
assert_eq!(signed(), [-42, -41, 100]);
|
2016-04-22 07:38:46 -05:00
|
|
|
assert!(unsafe_match());
|
|
|
|
}
|