diff --git a/src/glossary.md b/src/glossary.md index e48bcf4f9c..8df0e5550e 100644 --- a/src/glossary.md +++ b/src/glossary.md @@ -223,6 +223,7 @@ A type is zero sized (a ZST) if its size is 0. Such types have at most one possi - `repr(Rust)` [structs] with no fields or where all fields are zero sized (see [layout.repr.rust.struct-zst]). - `repr(C)` [structs] with no fields or where all fields are zero-sized (see [layout.repr.c.struct.size-field-offset]). - `repr(transparent)` [structs] with no fields or where all fields are zero-sized (see [layout.repr.transparent.layout-abi]). +- `repr(Rust)` [enums] (without a [primitive representation] specified) with no variants (see [layout.repr.rust.enum-empty-zst]) - `repr(Rust)` [enums] (without a [primitive representation] specified) with a single [field-struct-like variant], a single [unit-struct-like variant], or a single [tuple-struct-like variant] and where the struct-like thing has no fields or where all of the fields are zero sized (see [layout.repr.rust.enum-struct-like-zst]). - [Arrays] of zero-sized types (see [layout.array]). - [Arrays] of length zero (see [layout.array]). @@ -284,6 +285,8 @@ enum E5 { enum E6 { V1 (), } +# /// An enum with no variants. +enum E7 {} assert_eq!(0, size_of::<()>()); assert_eq!(0, size_of_val(&f)); @@ -304,6 +307,7 @@ assert_eq!(0, size_of::()); assert_eq!(0, size_of::()); assert_eq!(0, size_of::()); assert_eq!(0, size_of::()); +assert_eq!(0, size_of::()); ``` [`extern` blocks]: items.extern diff --git a/src/type-layout.md b/src/type-layout.md index db43a87394..ead5c948d2 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -183,6 +183,9 @@ Be aware that this guarantee does not imply that the fields have distinct addres r[layout.repr.rust.struct-zst] For [structs] with no fields or where all fields are [zero sized], it is further guaranteed that the structs are themselves [zero sized]. +r[layout.repr.rust.enum-empty-zst] +For [enums] (without a [primitive representation] specified) with no variants, the enums themselves are [zero sized]. + r[layout.repr.rust.enum-struct-like-zst] For [enums] (without a [primitive representation] specified) with a single [field-struct-like variant], a single [unit-struct-like variant], or a single [tuple-struct-like variant] and where the struct-like thing has no fields or where all of the fields are [zero sized], the enums themselves are [zero sized].