Skip to content

Commit bb51ae8

Browse files
committed
New rule layout.repr.rust.enum-empty-zst
1 parent 5011dcd commit bb51ae8

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/glossary.md

Lines changed: 3 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] (without a primitive representation specified) with zero variants (see [layout.repr.rust.enum-empty-zst])
226227
- `repr(Rust)` [enums] (without a primitive representation specified) with a single struct-like variant with no fields or where all fields are zero-sized (see [layout.repr.rust.enum-struct-like-zst])
227228
- [Arrays] of zero-sized types (see [layout.array]).
228229
- [Arrays] of length zero (see [layout.array]).
@@ -265,6 +266,7 @@ union U {
265266
enum E2 {
266267
V1 { f1: (), f2: [(); 10 ] },
267268
}
269+
enum E3 {}
268270
assert_eq!(0, size_of::<()>());
269271
assert_eq!(0, size_of_val(&f));
270272
assert_eq!(0, size_of_val(&S));
@@ -280,6 +282,7 @@ assert_eq!(0, size_of::<[(); 10]>());
280282
assert_eq!(0, size_of::<[u8; 0]>());
281283
assert_eq!(0, size_of::<U>());
282284
assert_eq!(0, size_of::<E2>());
285+
assert_eq!(0, size_of::<E3>());
283286
```
284287

285288
[`extern` blocks]: items.extern

src/type-layout.md

Lines changed: 3 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-empty-zst]
187+
For [enums] (without a primitive representation specified) with no variants, the enum itself is [zero-sized].
188+
186189
r[layout.repr.rust.enum-struct-like-zst]
187190
For [enums] (without a primitive representation specified) with a single struct-like variant with no fields or where all fields are [zero-sized], the enum itself is [zero-sized].
188191

0 commit comments

Comments
 (0)