Skip to content

Commit 6a2c83a

Browse files
New rule layout.repr.rust.enum-struct-like-zst
1 parent 4e32c14 commit 6a2c83a

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/glossary.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ A type is zero sized (a ZST) if its size is 0. Such types have at most one possi
223223
- `repr(Rust)` [structs] with no fields or where all fields are zero-sized (see [layout.repr.rust.struct-zst]).
224224
- `repr(C)` [structs] with no fields or where all fields are zero-sized (see [layout.repr.c.struct.size-field-offset]).
225225
- `repr(transparent)` [structs] with no fields or where all fields are zero-sized (see [layout.repr.transparent.layout-abi]).
226+
- `repr(Rust)` [enums] with a single struct-like variant with no fields or where all fields are zero-sized (see [layout.repr.rust.enum-struct-like-zst])
226227
- [Arrays] of zero-sized types (see [layout.array]).
227228
- [Arrays] of length zero (see [layout.array]).
228229
- [Unions] of zero-sized types (see [items.union.common-storage]).
@@ -261,6 +262,9 @@ union U {
261262
f2: [(); 10],
262263
f3: [u8; 0],
263264
}
265+
enum E2 {
266+
V1 { f1: (), f2: [(); 10 ] },
267+
}
264268
assert_eq!(0, size_of::<()>());
265269
assert_eq!(0, size_of_val(&f));
266270
assert_eq!(0, size_of_val(&S));
@@ -275,6 +279,7 @@ assert_eq!(0, size_of::<T2>());
275279
assert_eq!(0, size_of::<[(); 10]>());
276280
assert_eq!(0, size_of::<[u8; 0]>());
277281
assert_eq!(0, size_of::<U>());
282+
assert_eq!(0, size_of::<E2>());
278283
```
279284

280285
[`extern` blocks]: items.extern

src/type-layout.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ Be aware that this guarantee does not imply that the fields have distinct addres
183183
r[layout.repr.rust.struct-zst]
184184
For [structs] with no fields, or where all fields are [zero-sized], it is further guaranteed that the structs are themselves [zero-sized].
185185

186+
r[layout.repr.rust.enum-struct-like-zst]
187+
For [enums] with a single struct-like variant with no fields or where all fields are [zero-sized], the enum itself is [zero-sized].
188+
186189
r[layout.repr.rust.unspecified]
187190
There are no other guarantees of data layout made by this representation.
188191

@@ -559,6 +562,7 @@ Because this representation delegates type layout to another type, it cannot be
559562
[`Sized`]: std::marker::Sized
560563
[`Copy`]: std::marker::Copy
561564
[dynamically sized types]: dynamically-sized-types.md
565+
[enums]: items/enumerations.md
562566
[field-less enums]: items/enumerations.md#field-less-enum
563567
[fn-abi-compatibility]: ../core/primitive.fn.md#abi-compatibility
564568
[enumerations]: items/enumerations.md

0 commit comments

Comments
 (0)