diff options
Diffstat (limited to 'tests/ui/transmutability/enums/should_order_correctly.rs')
-rw-r--r-- | tests/ui/transmutability/enums/should_order_correctly.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/transmutability/enums/should_order_correctly.rs b/tests/ui/transmutability/enums/should_order_correctly.rs new file mode 100644 index 000000000..1335cc9d2 --- /dev/null +++ b/tests/ui/transmutability/enums/should_order_correctly.rs @@ -0,0 +1,36 @@ +// check-pass +//! The payloads of an enum variant should be ordered after its tag. + +#![crate_type = "lib"] +#![feature(transmutability)] +#![allow(dead_code)] + +mod assert { + use std::mem::{Assume, BikeshedIntrinsicFrom}; + pub struct Context; + + pub fn is_transmutable<Src, Dst>() + where + Dst: BikeshedIntrinsicFrom<Src, Context, { + Assume::ALIGNMENT + .and(Assume::LIFETIMES) + .and(Assume::SAFETY) + .and(Assume::VALIDITY) + }> + {} +} + +#[repr(u8)] enum V0 { V = 0 } +#[repr(u8)] enum V1 { V = 1 } +#[repr(u8)] enum V2 { V = 2 } + +#[repr(u8)] enum E01 { V0(V1) = 0u8 } +#[repr(u8)] enum E012 { V0(V1, V2) = 0u8 } + +fn should_order_tag_and_fields_correctly() { + // An implementation that (incorrectly) arranges E01 as [0x01, 0x00] will, + // in principle, reject this transmutation. + assert::is_transmutable::<E01, V0>(); + // Again, but with one more field. + assert::is_transmutable::<E012, E01>(); +} |