]> git.lizzy.rs Git - rust.git/blob - src/test/ui/layout/homogeneous-aggr-zero-sized-repr-rust.rs
Rollup merge of #99479 - Enselic:import-can-be-without-id, r=camelid
[rust.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 #[repr(C)]
23 pub struct WithEmptyRustStruct {
24     pub a: f32,
25     pub b: f32,
26     pub _unit: EmptyRustStruct,
27 }
28
29 pub struct TransitivelyEmptyRustStruct {
30     field: EmptyRustStruct,
31     array: [u32; 0],
32 }
33
34 #[repr(C)]
35 pub struct WithTransitivelyEmptyRustStruct {
36     pub a: f32,
37     pub b: f32,
38     pub _unit: TransitivelyEmptyRustStruct,
39 }
40
41 pub enum EmptyRustEnum {
42     Dummy,
43 }
44
45 #[repr(C)]
46 pub struct WithEmptyRustEnum {
47     pub a: f32,
48     pub b: f32,
49     pub _unit: EmptyRustEnum,
50 }
51
52 #[rustc_layout(homogeneous_aggregate)]
53 pub type Test1 = BaseCase;
54 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) }))
55
56 #[rustc_layout(homogeneous_aggregate)]
57 pub type Test2 = WithPhantomData;
58 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) }))
59
60 #[rustc_layout(homogeneous_aggregate)]
61 pub type Test3 = WithEmptyRustStruct;
62 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) }))
63
64 #[rustc_layout(homogeneous_aggregate)]
65 pub type Test4 = WithTransitivelyEmptyRustStruct;
66 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) }))
67
68 #[rustc_layout(homogeneous_aggregate)]
69 pub type Test5 = WithEmptyRustEnum;
70 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Float, size: Size(4 bytes) }))
71
72 fn main() {}