summaryrefslogtreecommitdiffstats
path: root/src/test/ui/transmutability/enums/should_respect_endianness.rs
blob: 67a3c4e94ba8fb17e971908237c777044b62ccee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! The target endianness should be a consideration in computing the layout of
//! an enum with a multi-byte tag.

#![crate_type = "lib"]
#![feature(arbitrary_enum_discriminant)]
#![feature(transmutability)]
#![allow(dead_code)]

mod assert {
    use std::mem::BikeshedIntrinsicFrom;
    pub struct Context;

    pub fn is_transmutable<Src, Dst>()
    where
        Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
    {}
}

#[repr(u16)] enum Src { V = 0xCAFE }

#[repr(u8)] enum OxCA { V = 0xCA }
#[repr(u8)] enum OxFE { V = 0xFE }

#[cfg(target_endian = "big")] #[repr(C)] struct Expected(OxCA, OxFE);
#[cfg(target_endian = "big")] #[repr(C)] struct Unexpected(OxFE, OxCA);

#[cfg(target_endian = "little")] #[repr(C)] struct Expected(OxFE, OxCA);
#[cfg(target_endian = "little")] #[repr(C)] struct Unexpected(OxCA, OxFE);

fn should_respect_endianness() {
    assert::is_transmutable::<Src, Expected>();
    assert::is_transmutable::<Src, Unexpected>(); //~ ERROR cannot be safely transmuted
}