]> git.lizzy.rs Git - rust.git/blob - tests/ui/print_type_sizes/packed.rs
Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-se
[rust.git] / tests / ui / print_type_sizes / packed.rs
1 // compile-flags: -Z print-type-sizes --crate-type=lib
2 // build-pass
3 // ignore-pass
4 // ^-- needed because `--pass check` does not emit the output needed.
5 //     FIXME: consider using an attribute instead of side-effects.
6
7 // This file illustrates how packing is handled; it should cause
8 // the elimination of padding that would normally be introduced
9 // to satisfy alignment desirata.
10 //
11 // It avoids using u64/i64 because on some targets that is only 4-byte
12 // aligned (while on most it is 8-byte aligned) and so the resulting
13 // padding and overall computed sizes can be quite different.
14
15 #![allow(dead_code)]
16
17 #[derive(Default)]
18 #[repr(packed)]
19 pub struct Packed1 {
20     a: u8,
21     b: u8,
22     g: i32,
23     c: u8,
24     h: i16,
25     d: u8,
26 }
27
28 #[derive(Default)]
29 #[repr(packed(2))]
30 pub struct Packed2 {
31     a: u8,
32     b: u8,
33     g: i32,
34     c: u8,
35     h: i16,
36     d: u8,
37 }
38
39 #[derive(Default)]
40 #[repr(packed(2))]
41 #[repr(C)]
42 pub struct Packed2C {
43     a: u8,
44     b: u8,
45     g: i32,
46     c: u8,
47     h: i16,
48     d: u8,
49 }
50
51 #[derive(Default)]
52 pub struct Padded {
53     a: u8,
54     b: u8,
55     g: i32,
56     c: u8,
57     h: i16,
58     d: u8,
59 }