Skip to content

Commit 7c443b7

Browse files
committed
Add layout guarantees for never type !
1 parent bfba255 commit 7c443b7

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/glossary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ r[glossary.zst]
217217
A type is zero sized (a ZST) if its size is 0. Such types have at most one possible value. Examples include:
218218

219219
- The [unit type] (see [layout.tuple.unit]).
220+
- The [never type] `!` (see [types.never.layout]).
220221
- [Function items] (see [type.fn-item.intro]).
221222
- The constructors of [tuple-like structs] (see [type.fn-item.intro]).
222223
- The constructors of [tuple-like enum variants] (see [type.fn-item.intro]).

src/type-layout.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The size of most primitives is given in this table.
4141
| `f32` | 4 |
4242
| `f64` | 8 |
4343
| `char` | 4 |
44+
| [`!`][never-type] | 0 |
4445

4546
r[layout.primitive.size-minimum]
4647
`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.
@@ -571,3 +572,4 @@ Because this representation delegates type layout to another type, it cannot be
571572
[structs]: items/structs.md
572573
[`transparent`]: #the-transparent-representation
573574
[`Layout`]: std::alloc::Layout
575+
[never-type]: types/never.md

src/types/never.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ Expressions of type `!` can be coerced into any type.
5555
> [!NOTE]
5656
> The standard library type [`Infallible`] is a type alias for `!`.
5757
58+
r[type.never.layout]
59+
The `!` type has a size of 0 and an alignment of 1.
60+
5861
[`Infallible`]: core::convert::Infallible

0 commit comments

Comments
 (0)