2021-07-03 16:18:13 +00:00
|
|
|
//! The target endianness should be a consideration in computing the layout of
|
|
|
|
//! an enum with a multi-byte tag.
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
#![feature(transmutability)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
mod assert {
|
2022-08-18 19:39:14 +00:00
|
|
|
use std::mem::{Assume, BikeshedIntrinsicFrom};
|
2021-07-03 16:18:13 +00:00
|
|
|
pub struct Context;
|
|
|
|
|
|
|
|
pub fn is_transmutable<Src, Dst>()
|
|
|
|
where
|
2022-08-18 19:39:14 +00:00
|
|
|
Dst: BikeshedIntrinsicFrom<Src, Context, {
|
|
|
|
Assume::ALIGNMENT
|
|
|
|
.and(Assume::LIFETIMES)
|
|
|
|
.and(Assume::SAFETY)
|
|
|
|
.and(Assume::VALIDITY)
|
|
|
|
}>
|
2021-07-03 16:18:13 +00:00
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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>();
|
2022-07-21 17:53:01 +00:00
|
|
|
assert::is_transmutable::<Src, Unexpected>(); //~ ERROR cannot be safely transmuted
|
2021-07-03 16:18:13 +00:00
|
|
|
}
|