]> git.proxmox.com Git - rustc.git/blob - src/test/ui/transmutability/unions/should_reject_intersecting.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / src / test / ui / transmutability / unions / should_reject_intersecting.rs
1 //! ALL valid bit patterns of the source must be valid bit patterns of the
2 //! destination type, unless validity is assumed.
3
4 #![crate_type = "lib"]
5 #![feature(transmutability)]
6 #![allow(dead_code, incomplete_features, non_camel_case_types)]
7
8 mod assert {
9 use std::mem::BikeshedIntrinsicFrom;
10 pub struct Context;
11
12 pub fn is_transmutable<Src, Dst>()
13 where
14 Dst: BikeshedIntrinsicFrom<Src, Context, false, false, false, true>
15 // validity is NOT assumed ----------------------------^^^^^
16 {}
17 }
18
19 #[derive(Clone, Copy)] #[repr(u8)] enum Ox00 { V = 0x00 }
20 #[derive(Clone, Copy)] #[repr(u8)] enum Ox7F { V = 0x7F }
21 #[derive(Clone, Copy)] #[repr(u8)] enum OxFF { V = 0xFF }
22
23 fn test() {
24 #[repr(C)]
25 union A {
26 a: Ox00,
27 b: Ox7F,
28 }
29
30 #[repr(C)]
31 union B {
32 a: Ox7F,
33 b: OxFF,
34 }
35
36 assert::is_transmutable::<A, B>(); //~ ERROR cannot be safely transmuted
37 assert::is_transmutable::<B, A>(); //~ ERROR cannot be safely transmuted
38 }