1 //! The variants of a union must be padded with uninit bytes such that they have
2 //! the same length (in bytes).
5 #![feature(transmutability)]
9 use std
::mem
::{Assume, BikeshedIntrinsicFrom}
;
11 pub fn is_transmutable
<Src
, Dst
, Context
>()
13 Dst
: BikeshedIntrinsicFrom
<Src
, Context
, {
15 .and(Assume
::LIFETIMES
)
17 .and(Assume
::VALIDITY
)
22 #[derive(Clone, Copy)]
23 #[repr(C)] struct Zst;
25 #[derive(Clone, Copy)]
26 #[repr(u8)] enum V0 { V = 0 }
28 #[derive(Clone, Copy)]
29 #[repr(u8)] enum V2 { V = 2 }
37 #[repr(C)] struct Src(V0, Zst, V2);
38 #[repr(C)] struct Dst(V0, Lopsided, V2);
40 fn should_pad_variants() {
42 // If the implementation (incorrectly) fails to pad `Lopsided::smol` with
43 // an uninitialized byte, this transmutation might be (wrongly) accepted:
44 assert
::is_transmutable
::<Src
, Dst
, Context
>(); //~ ERROR cannot be safely transmuted