From 75131fab2c4519fb42c23eb7a399ddbe8d428665 Mon Sep 17 00:00:00 2001 From: Zachary S Date: Wed, 8 Jul 2026 11:17:32 -0500 Subject: [PATCH 1/2] Add layout guarantees for never type `!` --- src/glossary.md | 1 + src/type-layout.md | 2 ++ src/types/never.md | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/src/glossary.md b/src/glossary.md index 80cf0f2624..59258393dc 100644 --- a/src/glossary.md +++ b/src/glossary.md @@ -220,6 +220,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]). diff --git a/src/type-layout.md b/src/type-layout.md index 70b26aac32..f4c7476701 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -41,6 +41,7 @@ The size of most primitives is given in this table. | `f32` | 4 | | `f64` | 8 | | `char` | 4 | +| [`!`][never-type] | 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. @@ -723,3 +724,4 @@ Because this representation delegates type layout to another type, it cannot be [unit-struct-like variant]: EnumVariant [`Layout`]: std::alloc::Layout [uninhabited]: glossary.uninhabited +[never-type]: types/never.md diff --git a/src/types/never.md b/src/types/never.md index 414862fe52..0fd7aba28e 100644 --- a/src/types/never.md +++ b/src/types/never.md @@ -52,6 +52,10 @@ 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 `!`. From c0374f29263ffa891d6e200a24ae30bcf74f6fbd Mon Sep 17 00:00:00 2001 From: Zachary S Date: Wed, 2 Sep 2026 00:04:35 -0500 Subject: [PATCH 2/2] Fix spacing in never type docs, and add never type `size_of` example. --- src/glossary.md | 1 + src/types/never.md | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glossary.md b/src/glossary.md index 59258393dc..7688b73235 100644 --- a/src/glossary.md +++ b/src/glossary.md @@ -293,6 +293,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/types/never.md b/src/types/never.md index 0fd7aba28e..6228795ff7 100644 --- a/src/types/never.md +++ b/src/types/never.md @@ -52,7 +52,6 @@ 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.