Skip to content

Commit

Permalink
transparent_enums: test alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jan 20, 2020
1 parent 93efe41 commit 25460eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/test/ui/repr/repr-transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ enum TooManyVariants { //~ ERROR transparent enum needs exactly one variant, but
Bar,
}

#[repr(transparent)]
enum NontrivialAlignZstEnum {
Foo(u32, [u16; 0]), //~ ERROR alignment larger than 1
}

#[repr(transparent)]
enum GenericAlignEnum<T> {
Foo { bar: ZstAlign32<T>, baz: u32 } //~ ERROR alignment larger than 1
}

#[repr(transparent)]
union UnitUnion { //~ ERROR transparent union needs exactly one non-zero-sized field, but has 0
u: (),
Expand Down
18 changes: 15 additions & 3 deletions src/test/ui/repr/repr-transparent.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,26 @@ LL | Foo(String),
LL | Bar,
| --- too many variants in `TooManyVariants`

error[E0691]: zero-sized field in transparent enum has alignment larger than 1
--> $DIR/repr-transparent.rs:65:14
|
LL | Foo(u32, [u16; 0]),
| ^^^^^^^^ has alignment larger than 1

error[E0691]: zero-sized field in transparent enum has alignment larger than 1
--> $DIR/repr-transparent.rs:70:11
|
LL | Foo { bar: ZstAlign32<T>, baz: u32 }
| ^^^^^^^^^^^^^^^^^^ has alignment larger than 1

error[E0690]: transparent union needs exactly one non-zero-sized field, but has 0
--> $DIR/repr-transparent.rs:64:1
--> $DIR/repr-transparent.rs:74:1
|
LL | union UnitUnion {
| ^^^^^^^^^^^^^^^ needs exactly one non-zero-sized field, but has 0

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

error: aborting due to 15 previous errors
error: aborting due to 17 previous errors

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

0 comments on commit 25460eb

Please sign in to comment.