]> git.lizzy.rs Git - rust.git/blob - src/test/ui/repr/repr-transparent.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[rust.git] / src / test / ui / repr / repr-transparent.rs
1 // This file tests repr(transparent)-related errors reported during typeck. Other errors
2 // that are reported earlier and therefore preempt these are tested in:
3 // - repr-transparent-other-reprs.rs
4 // - repr-transparent-other-items.rs
5
6 #![feature(repr_align)]
7
8 use std::marker::PhantomData;
9
10 #[repr(transparent)]
11 struct NoFields; //~ ERROR needs exactly one non-zero-sized field
12
13 #[repr(transparent)]
14 struct ContainsOnlyZst(()); //~ ERROR needs exactly one non-zero-sized field
15
16 #[repr(transparent)]
17 struct ContainsOnlyZstArray([bool; 0]); //~ ERROR needs exactly one non-zero-sized field
18
19 #[repr(transparent)]
20 struct ContainsMultipleZst(PhantomData<*const i32>, NoFields);
21 //~^ ERROR needs exactly one non-zero-sized field
22
23 #[repr(transparent)]
24 struct MultipleNonZst(u8, u8); //~ ERROR needs exactly one non-zero-sized field
25
26 trait Mirror { type It: ?Sized; }
27 impl<T: ?Sized> Mirror for T { type It = Self; }
28
29 #[repr(transparent)]
30 pub struct StructWithProjection(f32, <f32 as Mirror>::It);
31 //~^ ERROR needs exactly one non-zero-sized field
32
33 #[repr(transparent)]
34 struct NontrivialAlignZst(u32, [u16; 0]); //~ ERROR alignment larger than 1
35
36 #[repr(align(32))]
37 struct ZstAlign32<T>(PhantomData<T>);
38
39 #[repr(transparent)]
40 struct GenericAlign<T>(ZstAlign32<T>, u32); //~ ERROR alignment larger than 1
41
42 fn main() {}