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