2018-01-03 17:43:30 +01:00
|
|
|
// This file tests repr(transparent)-related errors reported during typeck. Other errors
|
|
|
|
// that are reported earlier and therefore preempt these are tested in:
|
|
|
|
// - repr-transparent-other-reprs.rs
|
|
|
|
// - repr-transparent-other-items.rs
|
|
|
|
|
2020-01-11 00:53:54 +01:00
|
|
|
#![feature(transparent_unions)]
|
2018-01-03 17:43:30 +01:00
|
|
|
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
2021-06-14 07:04:56 +09:00
|
|
|
struct NoFields;
|
2018-01-03 17:43:30 +01:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
2021-06-14 07:04:56 +09:00
|
|
|
struct ContainsOnlyZst(());
|
2018-01-03 17:43:30 +01:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
2021-06-14 07:04:56 +09:00
|
|
|
struct ContainsOnlyZstArray([bool; 0]);
|
2018-01-03 17:43:30 +01:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
struct ContainsMultipleZst(PhantomData<*const i32>, NoFields);
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
2021-06-14 07:04:56 +09:00
|
|
|
struct ContainsZstAndNonZst((), [i32; 2]);
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
2023-08-29 08:58:38 +02:00
|
|
|
struct MultipleNonZst(u8, u8); //~ ERROR needs at most one field with non-trivial size or alignment
|
2018-01-03 17:43:30 +01:00
|
|
|
|
|
|
|
trait Mirror { type It: ?Sized; }
|
|
|
|
impl<T: ?Sized> Mirror for T { type It = Self; }
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct StructWithProjection(f32, <f32 as Mirror>::It);
|
2023-08-29 08:58:38 +02:00
|
|
|
//~^ ERROR needs at most one field with non-trivial size or alignment
|
2018-01-03 17:43:30 +01:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
2023-08-29 08:58:38 +02:00
|
|
|
struct NontrivialAlignZst(u32, [u16; 0]); //~ ERROR needs at most one field with non-trivial size or alignment
|
2018-01-03 17:43:30 +01:00
|
|
|
|
|
|
|
#[repr(align(32))]
|
|
|
|
struct ZstAlign32<T>(PhantomData<T>);
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
2023-08-29 08:58:38 +02:00
|
|
|
struct GenericAlign<T>(ZstAlign32<T>, u32); //~ ERROR needs at most one field with non-trivial size or alignment
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
struct WrapsZstWithAlignment([i32; 0]);
|
2018-08-23 02:19:38 +03:00
|
|
|
|
2019-05-22 07:31:09 -07:00
|
|
|
#[repr(transparent)] //~ ERROR unsupported representation for zero-variant enum
|
2021-06-14 07:04:56 +09:00
|
|
|
enum Void {} //~ ERROR transparent enum needs exactly one variant, but has 0
|
2019-05-22 07:31:09 -07:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
2021-06-14 07:04:56 +09:00
|
|
|
enum FieldlessEnum {
|
2019-05-22 07:31:09 -07:00
|
|
|
Foo,
|
|
|
|
}
|
|
|
|
|
2021-06-14 07:04:56 +09:00
|
|
|
#[repr(transparent)]
|
|
|
|
enum UnitFieldEnum {
|
|
|
|
Foo(()),
|
|
|
|
}
|
|
|
|
|
2019-05-22 07:31:09 -07:00
|
|
|
#[repr(transparent)]
|
|
|
|
enum TooManyFieldsEnum {
|
|
|
|
Foo(u32, String),
|
|
|
|
}
|
2023-08-29 08:58:38 +02:00
|
|
|
//~^^^ ERROR transparent enum needs at most one field with non-trivial size or alignment, but has 2
|
2019-05-22 07:31:09 -07:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
2021-06-14 07:04:56 +09:00
|
|
|
enum MultipleVariants { //~ ERROR transparent enum needs exactly one variant, but has 2
|
2019-05-22 07:31:09 -07:00
|
|
|
Foo(String),
|
|
|
|
Bar,
|
|
|
|
}
|
|
|
|
|
2020-01-12 16:05:18 +01:00
|
|
|
#[repr(transparent)]
|
2023-08-29 08:58:38 +02:00
|
|
|
enum NontrivialAlignZstEnum { //~ ERROR needs at most one field with non-trivial size or alignment
|
|
|
|
Foo(u32, [u16; 0]),
|
2020-01-12 16:05:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
2023-08-29 08:58:38 +02:00
|
|
|
enum GenericAlignEnum<T> { //~ ERROR needs at most one field with non-trivial size or alignment
|
|
|
|
Foo { bar: ZstAlign32<T>, baz: u32 }
|
2020-01-12 16:05:18 +01:00
|
|
|
}
|
|
|
|
|
2019-05-22 07:31:09 -07:00
|
|
|
#[repr(transparent)]
|
2021-06-14 07:04:56 +09:00
|
|
|
union UnitUnion {
|
2019-05-22 07:31:09 -07:00
|
|
|
u: (),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
2023-08-29 08:58:38 +02:00
|
|
|
union TooManyFields { //~ ERROR transparent union needs at most one field with non-trivial size or alignment, but has 2
|
2019-05-22 07:31:09 -07:00
|
|
|
u: u32,
|
|
|
|
s: i32
|
|
|
|
}
|
|
|
|
|
2018-08-23 02:19:38 +03:00
|
|
|
fn main() {}
|