]> git.proxmox.com Git - rustc.git/blame - src/test/ui/transmutability/enums/should_order_correctly.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / transmutability / enums / should_order_correctly.rs
CommitLineData
064997fb
FG
1// check-pass
2//! The payloads of an enum variant should be ordered after its tag.
3
4#![crate_type = "lib"]
064997fb
FG
5#![feature(transmutability)]
6#![allow(dead_code)]
7
8mod assert {
f2b60f7d 9 use std::mem::{Assume, BikeshedIntrinsicFrom};
064997fb
FG
10 pub struct Context;
11
12 pub fn is_transmutable<Src, Dst>()
13 where
f2b60f7d
FG
14 Dst: BikeshedIntrinsicFrom<Src, Context, {
15 Assume::ALIGNMENT
16 .and(Assume::LIFETIMES)
17 .and(Assume::SAFETY)
18 .and(Assume::VALIDITY)
19 }>
064997fb
FG
20 {}
21}
22
23#[repr(u8)] enum V0 { V = 0 }
24#[repr(u8)] enum V1 { V = 1 }
25#[repr(u8)] enum V2 { V = 2 }
26
27#[repr(u8)] enum E01 { V0(V1) = 0u8 }
28#[repr(u8)] enum E012 { V0(V1, V2) = 0u8 }
29
30fn should_order_tag_and_fields_correctly() {
31 // An implementation that (incorrectly) arranges E01 as [0x01, 0x00] will,
32 // in principle, reject this transmutation.
33 assert::is_transmutable::<E01, V0>();
34 // Again, but with one more field.
35 assert::is_transmutable::<E012, E01>();
36}