]> git.proxmox.com Git - rustc.git/blob - src/test/ui/layout/homogeneous-aggr-zero-sized-repr-rust.rs
New upstream version 1.43.0+dfsg1
[rustc.git] / src / test / ui / layout / homogeneous-aggr-zero-sized-repr-rust.rs
1 #![feature(rustc_attrs)]
2
3 // Regression test for #56877. We want to ensure that the presence of
4 // `PhantomData` does not prevent `Bar` from being considered a
5 // homogeneous aggregate.
6
7 #[repr(C)]
8 pub struct BaseCase {
9 pub a: f32,
10 pub b: f32,
11 }
12
13 #[repr(C)]
14 pub struct WithPhantomData {
15 pub a: f32,
16 pub b: f32,
17 pub _unit: std::marker::PhantomData<()>,
18 }
19
20 pub struct EmptyRustStruct {
21 }
22
23 #[repr(C)]
24 pub struct WithEmptyRustStruct {
25 pub a: f32,
26 pub b: f32,
27 pub _unit: EmptyRustStruct,
28 }
29
30 pub struct TransitivelyEmptyRustStruct {
31 field: EmptyRustStruct,
32 array: [u32; 0],
33 }
34
35 #[repr(C)]
36 pub struct WithTransitivelyEmptyRustStruct {
37 pub a: f32,
38 pub b: f32,
39 pub _unit: TransitivelyEmptyRustStruct,
40 }
41
42 pub enum EmptyRustEnum {
43 Dummy,
44 }
45
46 #[repr(C)]
47 pub struct WithEmptyRustEnum {
48 pub a: f32,
49 pub b: f32,
50 pub _unit: EmptyRustEnum,
51 }
52
53 #[rustc_layout(homogeneous_aggregate)]
54 pub type Test1 = BaseCase;
55 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size { raw: 4 } }))
56
57 #[rustc_layout(homogeneous_aggregate)]
58 pub type Test2 = WithPhantomData;
59 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size { raw: 4 } }))
60
61 #[rustc_layout(homogeneous_aggregate)]
62 pub type Test3 = WithEmptyRustStruct;
63 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size { raw: 4 } }))
64
65 #[rustc_layout(homogeneous_aggregate)]
66 pub type Test4 = WithTransitivelyEmptyRustStruct;
67 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size { raw: 4 } }))
68
69 #[rustc_layout(homogeneous_aggregate)]
70 pub type Test5 = WithEmptyRustEnum;
71 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size { raw: 4 } }))
72
73 fn main() { }