Skip to content

Commit

Permalink
Merge pull request rust-lang#389 from Havvy/repr-transparent
Browse files Browse the repository at this point in the history
Document transparent representation
  • Loading branch information
matthewjasper authored Aug 20, 2018
2 parents 845d1ed + 622ceef commit d37b611
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/type-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,23 @@ Like all ways to create undefined behavior in safe Rust, this is a bug.

</div>

### The `transparent` Representation

The `transparent` representation can only be used on `struct`s that have a
single non-zero sized field and any number of zero-sized fields, including
[`PhantomData<T>`].

Structs with this representation have the same layout and ABI as the single
non-zero sized field.

This is different than the `C` representation because
a struct with the `C` representation will always have the ABI of a `C` `struct`
while, for example, a struct with the `transparent` representation with a
primitive field will have the ABI of the primitive field.

Because this representation delegates type layout to another type, it cannot be
used with any other representation.

[`align_of_val`]: ../std/mem/fn.align_of_val.html
[`size_of_val`]: ../std/mem/fn.size_of_val.html
[`align_of`]: ../std/mem/fn.align_of.html
Expand All @@ -312,3 +329,4 @@ Like all ways to create undefined behavior in safe Rust, this is a bug.
[zero-variant enumerations]: items/enumerations.html#zero-variant-enums
[undefined behavior]: behavior-considered-undefined.html
[27060]: https://github.com/rust-lang/rust/issues/27060
[`PhantomData<T>`]: special-types-and-traits.html#phantomdatat

0 comments on commit d37b611

Please sign in to comment.