]> git.lizzy.rs Git - rust.git/blob - src/test/ui/packed/packed-tuple-struct-layout.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / packed / packed-tuple-struct-layout.rs
1 // run-pass
2 use std::mem;
3
4 #[repr(packed)]
5 #[allow(unused_tuple_struct_fields)]
6 struct S4(u8,[u8; 3]);
7
8 #[repr(packed)]
9 #[allow(unused_tuple_struct_fields)]
10 struct S5(u8,u32);
11
12 pub fn main() {
13     unsafe {
14         let s4 = S4(1, [2,3,4]);
15         let transd : [u8; 4] = mem::transmute(s4);
16         assert_eq!(transd, [1, 2, 3, 4]);
17
18         let s5 = S5(1, 0xff_00_00_ff);
19         let transd : [u8; 5] = mem::transmute(s5);
20         // Don't worry about endianness, the u32 is palindromic.
21         assert_eq!(transd, [1, 0xff, 0, 0, 0xff]);
22     }
23 }