]> git.lizzy.rs Git - rust.git/blob - src/test/ui/repr/repr-transparent.rs
Auto merge of #100845 - timvermeulen:iter_compare, r=scottmcm
[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(transparent_unions)]
7
8 use std::marker::PhantomData;
9
10 #[repr(transparent)]
11 struct NoFields;
12
13 #[repr(transparent)]
14 struct ContainsOnlyZst(());
15
16 #[repr(transparent)]
17 struct ContainsOnlyZstArray([bool; 0]);
18
19 #[repr(transparent)]
20 struct ContainsMultipleZst(PhantomData<*const i32>, NoFields);
21
22 #[repr(transparent)]
23 struct ContainsZstAndNonZst((), [i32; 2]);
24
25 #[repr(transparent)]
26 struct MultipleNonZst(u8, u8); //~ ERROR needs at most one non-zero-sized field
27
28 trait Mirror { type It: ?Sized; }
29 impl<T: ?Sized> Mirror for T { type It = Self; }
30
31 #[repr(transparent)]
32 pub struct StructWithProjection(f32, <f32 as Mirror>::It);
33 //~^ ERROR needs at most one non-zero-sized field
34
35 #[repr(transparent)]
36 struct NontrivialAlignZst(u32, [u16; 0]); //~ ERROR alignment larger than 1
37
38 #[repr(align(32))]
39 struct ZstAlign32<T>(PhantomData<T>);
40
41 #[repr(transparent)]
42 struct GenericAlign<T>(ZstAlign32<T>, u32); //~ ERROR alignment larger than 1
43
44 #[repr(transparent)] //~ ERROR unsupported representation for zero-variant enum
45 enum Void {} //~ ERROR transparent enum needs exactly one variant, but has 0
46
47 #[repr(transparent)]
48 enum FieldlessEnum {
49     Foo,
50 }
51
52 #[repr(transparent)]
53 enum UnitFieldEnum {
54     Foo(()),
55 }
56
57 #[repr(transparent)]
58 enum TooManyFieldsEnum {
59     Foo(u32, String),
60 }
61 //~^^^ ERROR transparent enum needs at most one non-zero-sized field, but has 2
62
63 #[repr(transparent)]
64 enum MultipleVariants { //~ ERROR transparent enum needs exactly one variant, but has 2
65     Foo(String),
66     Bar,
67 }
68
69 #[repr(transparent)]
70 enum NontrivialAlignZstEnum {
71     Foo(u32, [u16; 0]), //~ ERROR alignment larger than 1
72 }
73
74 #[repr(transparent)]
75 enum GenericAlignEnum<T> {
76     Foo { bar: ZstAlign32<T>, baz: u32 } //~ ERROR alignment larger than 1
77 }
78
79 #[repr(transparent)]
80 union UnitUnion {
81     u: (),
82 }
83
84 #[repr(transparent)]
85 union TooManyFields { //~ ERROR transparent union needs at most one non-zero-sized field, but has 2
86     u: u32,
87     s: i32
88 }
89
90 fn main() {}