]> git.proxmox.com Git - rustc.git/blob - src/test/ui/union/union-transmute.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / union / union-transmute.rs
1 // run-pass
2 // revisions: mirunsafeck thirunsafeck
3 // [thirunsafeck]compile-flags: -Z thir-unsafeck
4
5 union U {
6 a: (u8, u8),
7 b: u16,
8 }
9
10 union W {
11 a: u32,
12 b: f32,
13 }
14
15 fn main() {
16 unsafe {
17 let mut u = U { a: (1, 1) };
18 assert_eq!(u.b, (1 << 8) + 1);
19 u.b = (2 << 8) + 2;
20 assert_eq!(u.a, (2, 2));
21
22 let mut w = W { a: 0b0_11111111_00000000000000000000000 };
23 assert_eq!(w.b, f32::INFINITY);
24 w.b = f32::NEG_INFINITY;
25 assert_eq!(w.a, 0b1_11111111_00000000000000000000000);
26 }
27 }