rust/tests/ui/repr/aligned_enum_cast.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
574 B
Rust
Raw Normal View History

2022-01-15 12:03:38 +00:00
//@ run-pass
// allows aligned custom discriminant enums to cast into other types
// See the issue #92464 for more info
#[allow(dead_code)]
#[repr(align(8))]
enum Aligned {
Zero = 0,
One = 1,
}
fn main() {
let aligned = Aligned::Zero;
let fo = aligned as u8;
2022-05-07 13:01:25 +00:00
println!("foo {}", fo);
2022-07-05 17:26:52 +00:00
assert_eq!(fo, 0);
2022-05-07 13:01:25 +00:00
println!("{}", tou8(Aligned::Zero));
2022-07-05 17:26:52 +00:00
assert_eq!(tou8(Aligned::Zero), 0);
2022-05-07 13:01:25 +00:00
}
#[inline(never)]
fn tou8(al: Aligned) -> u8 {
// Cast behind a function call so ConstProp does not see it
// (so that we can test codegen).
al as u8
2022-01-15 12:03:38 +00:00
}