Closed
Description
#[repr(transparent)]
struct X(()); // ERROR: needs exactly one non-zero-sized field, but has 0
But
#[repr(transparent)]
struct X<T>(T);
println!("{}", mem::align_of_val(&X(()))); // 1
println!("{}", mem::size_of_val(&X(()))); // 0
The reference says
The transparent representation can only be used on a struct or an enum with a single variant that has:
- a single field with non-zero size, and
- any number of fields with size 0 and alignment 1 (e.g. PhantomData).
I do not see a reason for this restriction. Maybe simply replace "a single" by "at most one" and remove the check.