]> git.proxmox.com Git - rustc.git/blob - src/test/ui/transmutability/enums/should_pad_variants.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / 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).
3
4 #![crate_type = "lib"]
5 #![feature(transmutability)]
6 #![allow(dead_code)]
7
8 mod assert {
9 use std::mem::BikeshedIntrinsicFrom;
10
11 pub fn is_transmutable<Src, Dst, Context>()
12 where
13 Dst: BikeshedIntrinsicFrom<Src, Context, true, true, true, true>
14 {}
15 }
16
17 #[derive(Clone, Copy)]
18 #[repr(C)] struct Zst;
19
20 #[derive(Clone, Copy)]
21 #[repr(u8)] enum V0 { V = 0 }
22
23 #[derive(Clone, Copy)]
24 #[repr(u8)] enum V2 { V = 2 }
25
26 #[repr(C, u8)]
27 enum Lopsided {
28 Smol(Zst),
29 Lorg(V0),
30 }
31
32 #[repr(C)] struct Src(V0, Zst, V2);
33 #[repr(C)] struct Dst(Lopsided, V2);
34
35 fn should_pad_variants() {
36 struct Context;
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
40 }