diff --git a/src/glossary.md b/src/glossary.md index af9dc4cecb..24f9bd3d0d 100644 --- a/src/glossary.md +++ b/src/glossary.md @@ -119,6 +119,7 @@ An *n-ZST* refers to a type that is zero sized (a [ZST]) and has an [alignment] Examples of 1-ZSTs include: - The [unit type] (see [layout.tuple.unit]). +- The [never type] (see [type.never.layout]). - `repr(C)` [structs] with no fields or where all fields are 1-ZSTs (see [layout.repr.c.struct.align] and [layout.repr.c.struct.size-field-offset]). - `repr(transparent)` [structs] with no fields or where all fields are 1-ZSTs (see [layout.repr.transparent.layout-abi]). - [Arrays] of 1-ZSTs (see [layout.array]). @@ -148,6 +149,7 @@ fn is_1_zst() -> bool { } assert!(is_1_zst::<()>()); +assert!(is_1_zst::()); assert!(is_1_zst::()); assert!(is_1_zst::()); assert!(is_1_zst::<[(); 10]>()); @@ -255,7 +257,7 @@ Compile-time or run-time behavior that is not specified. This may result in, but r[glossary.uninhabited] ### Uninhabited -A type is uninhabited if it has no constructors and therefore can never be instantiated. An uninhabited type is "empty" in the sense that there are no values of the type. The canonical example of an uninhabited type is the [never type] `!`, or an enum with no variants `enum Never { }`. Opposite of [Inhabited](#inhabited). +A type is uninhabited if it has no constructors and therefore can never be instantiated. An uninhabited type is "empty" in the sense that there are no values of the type. The canonical example of an uninhabited type is the [never type] (`!`), or an enum with no variants (e.g., `enum Never { }`). Opposite of [Inhabited](#inhabited). > [!NOTE] > Uninhabited types are not necessarily [zero sized]. For example, `enum Never { }` is uninhabited and zero sized, but `(u8, Never)` is uninhabited and not zero sized. @@ -266,6 +268,7 @@ r[glossary.zst] A type is zero sized (a ZST) if its size is 0. Such types have at most one possible value. Examples include: - The [unit type] (see [layout.tuple.unit]). +- The [never type] (see [type.never.layout]). - [Function items] (see [type.fn-item.intro]). - The constructors of [tuple-like structs] (see [type.fn-item.intro]). - The constructors of [tuple-like enum variants] (see [type.fn-item.intro]). @@ -340,6 +343,7 @@ enum E6 { enum E7 {} assert_eq!(0, size_of::<()>()); +assert_eq!(0, size_of::()); assert_eq!(0, size_of_val(&f)); assert_eq!(0, size_of_val(&S)); assert_eq!(0, size_of_val(&E::V)); diff --git a/src/type-layout.md b/src/type-layout.md index daec57f9ea..9d56ea7570 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -42,6 +42,7 @@ The size of most primitives is given in this table. | `f32` | 4 | | `f64` | 8 | | `char` | 4 | +| `!` | 0 | r[layout.primitive.size-minimum] `usize` and `isize` have a size big enough to contain every address on the target platform. For example, on a 32 bit target, this is 4 bytes, and on a 64 bit target, this is 8 bytes. diff --git a/src/types/never.md b/src/types/never.md index 414862fe52..6228795ff7 100644 --- a/src/types/never.md +++ b/src/types/never.md @@ -52,6 +52,9 @@ NeverType -> `!` r[type.never.coercion] Expressions of type `!` can be coerced into any type. +r[type.never.layout] +The `!` type has a size of 0 and an alignment of 1. + > [!NOTE] > The standard library type [`Infallible`] is a type alias for `!`.