Skip to content

Commit

Permalink
Merge pull request #741 from rust-lang/transparent-enum
Browse files Browse the repository at this point in the history
`enum`s can now be `#[repr(transparent)]`
  • Loading branch information
ehuss committed Apr 8, 2020
2 parents da3098c + 4515957 commit f8dce93
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/type-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,14 @@ Like all ways to create undefined behavior in safe Rust, this is a bug.

### The `transparent` Representation

The `transparent` representation can only be used on `struct`s that have:
The `transparent` representation can only be used on a [`struct`][structs]
or an [`enum`][enumerations] 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<T>`]).

Structs with this representation have the same layout and ABI as the single
non-zero sized field.
Structs and enums 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`
Expand All @@ -380,12 +381,14 @@ used with any other representation.
[`Sized`]: ../std/marker/trait.Sized.html
[dynamically sized types]: dynamically-sized-types.md
[C-like enumerations]: items/enumerations.md#custom-discriminant-values-for-fieldless-enumerations
[enumerations]: items/enumerations.md
[zero-variant enumerations]: items/enumerations.md#zero-variant-enums
[undefined behavior]: behavior-considered-undefined.md
[27060]: https://github.com/rust-lang/rust/issues/27060
[`PhantomData<T>`]: special-types-and-traits.md#phantomdatat
[Default]: #the-default-representation
[`C`]: #the-c-representation
[primitive representations]: #primitive-representations
[structs]: items/structs.md
[`transparent`]: #the-transparent-representation
[`Layout`]: ../std/alloc/struct.Layout.html

0 comments on commit f8dce93

Please sign in to comment.