]>
Commit | Line | Data |
---|---|---|
2c00a5a8 XL |
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 | ||
dfeec247 | 6 | #![feature(transparent_unions)] |
2c00a5a8 XL |
7 | |
8 | use std::marker::PhantomData; | |
9 | ||
10 | #[repr(transparent)] | |
136023e0 | 11 | struct NoFields; |
2c00a5a8 XL |
12 | |
13 | #[repr(transparent)] | |
136023e0 | 14 | struct ContainsOnlyZst(()); |
2c00a5a8 XL |
15 | |
16 | #[repr(transparent)] | |
136023e0 | 17 | struct ContainsOnlyZstArray([bool; 0]); |
2c00a5a8 XL |
18 | |
19 | #[repr(transparent)] | |
20 | struct ContainsMultipleZst(PhantomData<*const i32>, NoFields); | |
2c00a5a8 XL |
21 | |
22 | #[repr(transparent)] | |
136023e0 XL |
23 | struct ContainsZstAndNonZst((), [i32; 2]); |
24 | ||
25 | #[repr(transparent)] | |
26 | struct MultipleNonZst(u8, u8); //~ ERROR needs at most one non-zero-sized field | |
2c00a5a8 XL |
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); | |
136023e0 | 33 | //~^ ERROR needs at most one non-zero-sized field |
2c00a5a8 XL |
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 | |
b7449926 | 43 | |
dc9dc135 | 44 | #[repr(transparent)] //~ ERROR unsupported representation for zero-variant enum |
136023e0 | 45 | enum Void {} //~ ERROR transparent enum needs exactly one variant, but has 0 |
dc9dc135 XL |
46 | |
47 | #[repr(transparent)] | |
136023e0 | 48 | enum FieldlessEnum { |
dc9dc135 XL |
49 | Foo, |
50 | } | |
51 | ||
136023e0 XL |
52 | #[repr(transparent)] |
53 | enum UnitFieldEnum { | |
54 | Foo(()), | |
55 | } | |
56 | ||
dc9dc135 XL |
57 | #[repr(transparent)] |
58 | enum TooManyFieldsEnum { | |
59 | Foo(u32, String), | |
60 | } | |
136023e0 | 61 | //~^^^ ERROR transparent enum needs at most one non-zero-sized field, but has 2 |
dc9dc135 XL |
62 | |
63 | #[repr(transparent)] | |
136023e0 | 64 | enum MultipleVariants { //~ ERROR transparent enum needs exactly one variant, but has 2 |
dc9dc135 XL |
65 | Foo(String), |
66 | Bar, | |
67 | } | |
68 | ||
dfeec247 XL |
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 | ||
dc9dc135 | 79 | #[repr(transparent)] |
136023e0 | 80 | union UnitUnion { |
dc9dc135 XL |
81 | u: (), |
82 | } | |
83 | ||
84 | #[repr(transparent)] | |
136023e0 | 85 | union TooManyFields { //~ ERROR transparent union needs at most one non-zero-sized field, but has 2 |
dc9dc135 XL |
86 | u: u32, |
87 | s: i32 | |
88 | } | |
89 | ||
b7449926 | 90 | fn main() {} |