]> git.proxmox.com Git - rustc.git/blob - src/test/ui/packed/packed-struct-generic-layout.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / packed / packed-struct-generic-layout.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(overflowing_literals)]
4
5
6 use std::mem;
7
8 #[repr(packed)]
9 struct S<T, S> {
10 a: T,
11 b: u8,
12 c: S
13 }
14
15 pub fn main() {
16 unsafe {
17 let s = S { a: 0xff_ff_ff_ffu32, b: 1, c: 0xaa_aa_aa_aa as i32 };
18 let transd : [u8; 9] = mem::transmute(s);
19 // Don't worry about endianness, the numbers are palindromic.
20 assert_eq!(transd,
21 [0xff, 0xff, 0xff, 0xff,
22 1,
23 0xaa, 0xaa, 0xaa, 0xaa]);
24
25
26 let s = S { a: 1u8, b: 2u8, c: 0b10000001_10000001 as i16};
27 let transd : [u8; 4] = mem::transmute(s);
28 // Again, no endianness problems.
29 assert_eq!(transd,
30 [1, 2, 0b10000001, 0b10000001]);
31 }
32 }