Description
PR #31 identified this as an area for continued discussion. Specifically, if you have a struct with single field (struct Foo { x: T }
), should we guarantee that the memory layout of Foo
is identical to the memory layout of T
(note that ABI details around function calls may still draw a distinction, which is why #[repr(transparent)]
is needed). What about zero-sized types like PhantomData
?
Long ago I proposed that we might want to guarantee (some subset of) newtype unpacking for repr(Rust) structs. @nikomatsakis carried this over into #11 as discussion point but it received no further discussion. I like to think that means it's uncontroversial 😄 I've also never heard of any reason why one might not want that to be true.
To make a specific proposal, let's restrict it to structs [1] that contain a single field having the same memory layout as the type of the sole field. So
struct Foo<T>(T);
andstruct Foo<T> { x: T }
would be laid out likeT
in memory, though possibly still passed differently in function calls.[1] The same guarantee for
(T,)
are already covered by the special case of homogeneous tuples being laid out like arrays that is already in this PR.