Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/glossary.md

@tgross35 tgross35 Sep 30, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has tests for size. Should it also have a test for alignment? Or is that covered elsewhere?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should have tests for alignment, but we don't have tests for other types' alignments in the reference (including bool which is also guaranteed to have an alignment of 1 (AFAICT we don't have tests for bool's size or alignment in the reference or rust-lang/rust)), so I don't think we need to add it in this PR (especially not the "Zero-sized type" section, which is specifically about size).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened rust-lang/rust#163570 to add tests for ! (and bool)'s size/align to coretests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size-1 types cannot have any alignment other than 1 anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -148,6 +149,7 @@ fn is_1_zst<T>() -> bool {
}

assert!(is_1_zst::<()>());
assert!(is_1_zst::<!>());
assert!(is_1_zst::<C1>());
assert!(is_1_zst::<C2>());
assert!(is_1_zst::<[(); 10]>());
Expand Down Expand Up @@ -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.
Expand All @@ -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]).
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/type-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/types/never.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `!`.

Expand Down
Loading