]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/transmutability/enums/should_pad_variants.rs
1 //! The variants of an enum must be padded with uninit bytes such that they have
2 //! the same length (in bytes).
5 #![feature(transmutability)]
9 use std
::mem
::BikeshedIntrinsicFrom
;
11 pub fn is_transmutable
<Src
, Dst
, Context
>()
13 Dst
: BikeshedIntrinsicFrom
<Src
, Context
, true, true, true, true>
17 #[derive(Clone, Copy)]
18 #[repr(C)] struct Zst;
20 #[derive(Clone, Copy)]
21 #[repr(u8)] enum V0 { V = 0 }
23 #[derive(Clone, Copy)]
24 #[repr(u8)] enum V2 { V = 2 }
32 #[repr(C)] struct Src(V0, Zst, V2);
33 #[repr(C)] struct Dst(Lopsided, V2);
35 fn should_pad_variants() {
37 // If the implementation (incorrectly) fails to pad `Lopsided::Smol` with
38 // an uninitialized byte, this transmutation might be (wrongly) accepted:
39 assert
::is_transmutable
::<Src
, Dst
, Context
>(); //~ ERROR cannot be safely transmuted