Skip to content

Commit 622ceef

Browse files
committed
Document transparent representation
1 parent 13d9a03 commit 622ceef

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/type-layout.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,23 @@ Like all ways to create undefined behavior in safe Rust, this is a bug.
302302

303303
</div>
304304

305+
### The `transparent` Representation
306+
307+
The `transparent` representation can only be used on `struct`s that have a
308+
single non-zero sized field and any number of zero-sized fields, including
309+
[`PhantomData<T>`].
310+
311+
Structs with this representation have the same layout and ABI as the single
312+
non-zero sized field.
313+
314+
This is different than the `C` representation because
315+
a struct with the `C` representation will always have the ABI of a `C` `struct`
316+
while, for example, a struct with the `transparent` representation with a
317+
primitive field will have the ABI of the primitive field.
318+
319+
Because this representation delegates type layout to another type, it cannot be
320+
used with any other representation.
321+
305322
[`align_of_val`]: ../std/mem/fn.align_of_val.html
306323
[`size_of_val`]: ../std/mem/fn.size_of_val.html
307324
[`align_of`]: ../std/mem/fn.align_of.html
@@ -312,3 +329,4 @@ Like all ways to create undefined behavior in safe Rust, this is a bug.
312329
[zero-variant enumerations]: items/enumerations.html#zero-variant-enums
313330
[undefined behavior]: behavior-considered-undefined.html
314331
[27060]: https://github.com/rust-lang/rust/issues/27060
332+
[`PhantomData<T>`]: special-types-and-traits.html#phantomdatat

0 commit comments

Comments
 (0)