1 //! The target endianness should be a consideration in computing the layout of
2 //! an enum with a multi-byte tag.
3
4 #![crate_type = "lib"]
5 #![feature(transmutability)]
6 #![allow(dead_code)]
7
8 mod assert {
9 use std::mem::{Assume, BikeshedIntrinsicFrom};
10 pub struct Context;
11
is_transmutable<Src, Dst>() where Dst: BikeshedIntrinsicFrom<Src, Context,12 pub fn is_transmutable<Src, Dst>()
13 where
14 Dst: BikeshedIntrinsicFrom<Src, Context, {
15 Assume::ALIGNMENT
16 .and(Assume::LIFETIMES)
17 .and(Assume::SAFETY)
18 .and(Assume::VALIDITY)
19 }>
20 {}
21 }
22
23 #[repr(u16)] enum Src { V = 0xCAFE }
24
25 #[repr(u8)] enum OxCA { V = 0xCA }
26 #[repr(u8)] enum OxFE { V = 0xFE }
27
28 #[cfg(target_endian = "big")] #[repr(C)] struct Expected(OxCA, OxFE);
29 #[cfg(target_endian = "big")] #[repr(C)] struct Unexpected(OxFE, OxCA);
30
31 #[cfg(target_endian = "little")] #[repr(C)] struct Expected(OxFE, OxCA);
32 #[cfg(target_endian = "little")] #[repr(C)] struct Unexpected(OxCA, OxFE);
33
should_respect_endianness()34 fn should_respect_endianness() {
35 assert::is_transmutable::<Src, Expected>();
36 assert::is_transmutable::<Src, Unexpected>(); //~ ERROR cannot be safely transmuted
37 }
38