rust/tests/pass/c_enums.rs

35 lines
677 B
Rust
Raw Normal View History

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