Skip to content

Commit f8dce93

Browse files
authored
Merge pull request #741 from rust-lang/transparent-enum
`enum`s can now be `#[repr(transparent)]`
2 parents da3098c + 4515957 commit f8dce93

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/type-layout.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,14 @@ Like all ways to create undefined behavior in safe Rust, this is a bug.
357357

358358
### The `transparent` Representation
359359

360-
The `transparent` representation can only be used on `struct`s that have:
360+
The `transparent` representation can only be used on a [`struct`][structs]
361+
or an [`enum`][enumerations] with a single variant that has:
361362

362363
- a single field with non-zero size, and
363364
- any number of fields with size 0 and alignment 1 (e.g. [`PhantomData<T>`]).
364365

365-
Structs with this representation have the same layout and ABI as the single
366-
non-zero sized field.
366+
Structs and enums with this representation have the same layout and ABI
367+
as the single non-zero sized field.
367368

368369
This is different than the `C` representation because
369370
a struct with the `C` representation will always have the ABI of a `C` `struct`
@@ -380,12 +381,14 @@ used with any other representation.
380381
[`Sized`]: ../std/marker/trait.Sized.html
381382
[dynamically sized types]: dynamically-sized-types.md
382383
[C-like enumerations]: items/enumerations.md#custom-discriminant-values-for-fieldless-enumerations
384+
[enumerations]: items/enumerations.md
383385
[zero-variant enumerations]: items/enumerations.md#zero-variant-enums
384386
[undefined behavior]: behavior-considered-undefined.md
385387
[27060]: https://github.com/rust-lang/rust/issues/27060
386388
[`PhantomData<T>`]: special-types-and-traits.md#phantomdatat
387389
[Default]: #the-default-representation
388390
[`C`]: #the-c-representation
389391
[primitive representations]: #primitive-representations
392+
[structs]: items/structs.md
390393
[`transparent`]: #the-transparent-representation
391394
[`Layout`]: ../std/alloc/struct.Layout.html

0 commit comments

Comments
 (0)