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
6 #![feature(transparent_unions)]
8 use std::marker::PhantomData;
14 struct ContainsOnlyZst(());
17 struct ContainsOnlyZstArray([bool; 0]);
20 struct ContainsMultipleZst(PhantomData<*const i32>, NoFields);
23 struct ContainsZstAndNonZst((), [i32; 2]);
26 struct MultipleNonZst(u8, u8); //~ ERROR needs at most one non-zero-sized field
28 trait Mirror { type It: ?Sized; }
29 impl<T: ?Sized> Mirror for T { type It = Self; }
32 pub struct StructWithProjection(f32, <f32 as Mirror>::It);
33 //~^ ERROR needs at most one non-zero-sized field
36 struct NontrivialAlignZst(u32, [u16; 0]); //~ ERROR alignment larger than 1
39 struct ZstAlign32<T>(PhantomData<T>);
42 struct GenericAlign<T>(ZstAlign32<T>, u32); //~ ERROR alignment larger than 1
44 #[repr(transparent)] //~ ERROR unsupported representation for zero-variant enum
45 enum Void {} //~ ERROR transparent enum needs exactly one variant, but has 0
58 enum TooManyFieldsEnum {
61 //~^^^ ERROR transparent enum needs at most one non-zero-sized field, but has 2
64 enum MultipleVariants { //~ ERROR transparent enum needs exactly one variant, but has 2
70 enum NontrivialAlignZstEnum {
71 Foo(u32, [u16; 0]), //~ ERROR alignment larger than 1
75 enum GenericAlignEnum<T> {
76 Foo { bar: ZstAlign32<T>, baz: u32 } //~ ERROR alignment larger than 1
85 union TooManyFields { //~ ERROR transparent union needs at most one non-zero-sized field, but has 2