Skip to content

Commit 25460eb

Browse files
committed
transparent_enums: test alignment
1 parent 93efe41 commit 25460eb

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/test/ui/repr/repr-transparent.rs

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ enum TooManyVariants { //~ ERROR transparent enum needs exactly one variant, but
6060
Bar,
6161
}
6262

63+
#[repr(transparent)]
64+
enum NontrivialAlignZstEnum {
65+
Foo(u32, [u16; 0]), //~ ERROR alignment larger than 1
66+
}
67+
68+
#[repr(transparent)]
69+
enum GenericAlignEnum<T> {
70+
Foo { bar: ZstAlign32<T>, baz: u32 } //~ ERROR alignment larger than 1
71+
}
72+
6373
#[repr(transparent)]
6474
union UnitUnion { //~ ERROR transparent union needs exactly one non-zero-sized field, but has 0
6575
u: (),

src/test/ui/repr/repr-transparent.stderr

+15-3
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,26 @@ LL | Foo(String),
9494
LL | Bar,
9595
| --- too many variants in `TooManyVariants`
9696

97+
error[E0691]: zero-sized field in transparent enum has alignment larger than 1
98+
--> $DIR/repr-transparent.rs:65:14
99+
|
100+
LL | Foo(u32, [u16; 0]),
101+
| ^^^^^^^^ has alignment larger than 1
102+
103+
error[E0691]: zero-sized field in transparent enum has alignment larger than 1
104+
--> $DIR/repr-transparent.rs:70:11
105+
|
106+
LL | Foo { bar: ZstAlign32<T>, baz: u32 }
107+
| ^^^^^^^^^^^^^^^^^^ has alignment larger than 1
108+
97109
error[E0690]: transparent union needs exactly one non-zero-sized field, but has 0
98-
--> $DIR/repr-transparent.rs:64:1
110+
--> $DIR/repr-transparent.rs:74:1
99111
|
100112
LL | union UnitUnion {
101113
| ^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0
102114

103115
error[E0690]: transparent union needs exactly one non-zero-sized field, but has 2
104-
--> $DIR/repr-transparent.rs:69:1
116+
--> $DIR/repr-transparent.rs:79:1
105117
|
106118
LL | union TooManyFields {
107119
| ^^^^^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 2
@@ -110,7 +122,7 @@ LL | u: u32,
110122
LL | s: i32
111123
| ------ this field is non-zero-sized
112124

113-
error: aborting due to 15 previous errors
125+
error: aborting due to 17 previous errors
114126

115127
Some errors have detailed explanations: E0084, E0690, E0691, E0731.
116128
For more information about an error, try `rustc --explain E0084`.

0 commit comments

Comments
 (0)