Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ r[glossary.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).

> [!NOTE]
> Uninhabited types are not necessarily [zero-sized][glossary.zst]. For example, `enum Never { }` is uninhabited and zero-sized, but `(u8, Never)` is uninhabited and not zero-sized.

r[glossary.zst]
### Zero-sized type (ZST)

Expand All @@ -223,6 +226,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])

@steffahn steffahn Jul 8, 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.

@zachs18

it feels inconsistent not to list ! here as well? Or is the size of ! not guaranteed?

I think ! should be listed in the primitives section, not the repr(Rust) section. I'll make a separate PR for that, since this one is already in FCP.

I was looking at the list in the glossary, actually ^^ - sorry for any potential confusion by not including a more precise reference to what I was talking about.

View changes since the review

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.

By having ! in the previous glossary entry, but not this section, one could be made to wonder whether it’s intentionally not included here as any sort of meaningful distinction. (I know these are just lists of examples, technically.)

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.

Added in #2309

- `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]).
Expand Down Expand Up @@ -284,6 +288,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));
Expand All @@ -304,6 +310,7 @@ assert_eq!(0, size_of::<E3>());
assert_eq!(0, size_of::<E4>());
assert_eq!(0, size_of::<E5>());
assert_eq!(0, size_of::<E6>());
assert_eq!(0, size_of::<E7>());
```

[`extern` blocks]: items.extern
Expand Down
7 changes: 7 additions & 0 deletions src/type-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ 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].

> [!NOTE]
> Such enums are [uninhabited].

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].

Expand Down Expand Up @@ -648,3 +654,4 @@ Because this representation delegates type layout to another type, it cannot be
[tuple-struct-like variant]: EnumVariantTuple
[unit-struct-like variant]: EnumVariant
[`Layout`]: std::alloc::Layout
[uninhabited]: glossary.uninhabited
Loading