Skip to content

Commit 5dccc8b

Browse files
committed
Clarify layout of enums with a single variant
1 parent a2be58b commit 5dccc8b

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

Diff for: reference/src/layout/enums.md

+9-28
Original file line numberDiff line numberDiff line change
@@ -351,47 +351,28 @@ enum Enum1<T> {
351351
}
352352
```
353353

354-
### Layout of single variant enums
354+
### Layout of enums with a single variant
355355

356356
> **NOTE**: the guarantees in this section have not been approved by an RFC process.
357357

358-
**Single variant data-carrying*** enums without a `repr()` annotation have the
359-
same layout as the variant field. **Single variant fieldless** enums have the
360-
same layout as a unit struct.
358+
**Data-carrying** enums with a single variant without a `repr()` annotation have
359+
the same SAFNC-layout as the variant field. **Fieldless** enums with a single variant
360+
have the same SAFNC-layout as a unit struct.
361361

362-
Here:
362+
For example, here:
363363

364364
```rust
365-
# use std::mem::{size_of, align_of};
366365
struct UnitStruct;
367-
enum SingleVariantFieldless { FieldlessVariant }
368-
# fn main() {
369-
assert_eq!(size_of::<SingleVariantFieldless>(), size_of::<UnitStruct>());
370-
assert_eq!(align_of::<SingleVariantFieldless>(), align_of::<UnitStruct>());
371-
// assert_eq!(call_abi_of::<SingleVariantFieldless>(), call_abi_of::<UnitStruct>());
372-
// assert_eq!(niches_of::<SingleVariantFieldless>(), niches_of::<UnitStruct>());
373-
# }
374-
```
375-
376-
the single-variant fieldless enum `SingleVariantFieldless` has the same layout
377-
as `UnitStruct`.
366+
enum FieldlessSingleVariant { FieldlessVariant }
378367

379-
Here:
380-
381-
```rust
382-
# use std::mem::{size_of, align_of};
383368
struct SomeStruct { x: u32 }
384-
enum SingleVariantDataCarrying {
369+
enum DataCarryingSingleVariant {
385370
DataCarryingVariant(SomeStruct),
386371
}
387-
# fn main() {
388-
# assert_eq!(size_of::<SingleVariantDataCarrying>(), size_of::<SomeStruct>());
389-
# assert_eq!(align_of::<SingleVariantDataCarrying>(), align_of::<SomeStruct>());
390-
# }
391372
```
392373

393-
the single-variant data-carrying enum `SingleVariantDataCarrying` has the same
394-
layout as `SomeStruct`.
374+
* `FieldSingleVariant` has the same SAFNC-layout as `UnitStruct`,
375+
* `DataCarryingSingleVariant` has the same SAFNC-layout as `SomeStruct`.
395376

396377
### Layout of multi-variant enums with one inhabited variant
397378

0 commit comments

Comments
 (0)