]> git.lizzy.rs Git - rust.git/blob - src/test/ui/union/union-transmute.rs
ac7dede98a3a347de164b415ccda9a0406db8b0f
[rust.git] / src / test / ui / union / union-transmute.rs
1 // run-pass
2
3 extern crate core;
4 use core::f32;
5
6 union U {
7     a: (u8, u8),
8     b: u16,
9 }
10
11 union W {
12     a: u32,
13     b: f32,
14 }
15
16 fn main() {
17     unsafe {
18         let mut u = U { a: (1, 1) };
19         assert_eq!(u.b, (1 << 8) + 1);
20         u.b = (2 << 8) + 2;
21         assert_eq!(u.a, (2, 2));
22
23         let mut w = W { a: 0b0_11111111_00000000000000000000000 };
24         assert_eq!(w.b, f32::INFINITY);
25         w.b = f32::NEG_INFINITY;
26         assert_eq!(w.a, 0b1_11111111_00000000000000000000000);
27     }
28 }