From 25460ebef6ae94494fc89a736a2f51bef2ea55c3 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 12 Jan 2020 16:05:18 +0100 Subject: [PATCH] transparent_enums: test alignment --- src/test/ui/repr/repr-transparent.rs | 10 ++++++++++ src/test/ui/repr/repr-transparent.stderr | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/test/ui/repr/repr-transparent.rs b/src/test/ui/repr/repr-transparent.rs index 969a323238f..8fbdb4cc80b 100644 --- a/src/test/ui/repr/repr-transparent.rs +++ b/src/test/ui/repr/repr-transparent.rs @@ -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 { + Foo { bar: ZstAlign32, 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: (), diff --git a/src/test/ui/repr/repr-transparent.stderr b/src/test/ui/repr/repr-transparent.stderr index f0c1fbe8ac9..cbc74fbb6a2 100644 --- a/src/test/ui/repr/repr-transparent.stderr +++ b/src/test/ui/repr/repr-transparent.stderr @@ -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, 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 @@ -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`.