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
573 B
Rust
Raw Normal View History

2022-01-15 06:03:38 -06: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 08:01:25 -05:00
println!("foo {}", fo);
2022-07-05 12:26:52 -05:00
assert_eq!(fo, 0);
2022-05-07 08:01:25 -05:00
println!("{}", tou8(Aligned::Zero));
2022-07-05 12:26:52 -05:00
assert_eq!(tou8(Aligned::Zero), 0);
2022-05-07 08:01:25 -05: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 06:03:38 -06:00
}