reference
reference copied to clipboard
Clarify that #[repr(transparent)] is valid without a non-ZST field
The following is valid, but the prior language suggests it is not:
#[repr(transparent)]
enum Banana {
Phone,
}
#[repr(transparent)]
struct Blooey(());
#[repr(transparent)]
struct Orange;
Of note: it's still invalid to have a zero-sized field in a transparent struct that has an alignment requirement higher than 1:
#[repr(align(2))]
struct Inner;
// error[E0691]: zero-sized field in transparent struct has alignment
// larger than 1
#[repr(transparent)]
struct Fizz(Inner);
An extension on that align-2 weirdness: it's valid to express in generic code, but not concretely. Rustc bug?
// This is just fine, because it's generic?
#[repr(transparent)]
struct Fizz<T = Inner>(T, [(); 10]);
Looks like https://github.com/rust-lang/rust/issues/100954 is already tracking the inconsistencies with #[repr(transparent)]