From 399f597bc3b4caaa68bd0e2c56c79c74913e67e0 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Tue, 10 Mar 2026 12:51:21 -0700 Subject: [PATCH] Glossary: add new entry documenting zero-sized types --- src/glossary.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/glossary.md b/src/glossary.md index 9d39173e01..109d5daad0 100644 --- a/src/glossary.md +++ b/src/glossary.md @@ -211,6 +211,27 @@ 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). +r[glossary.zst] +### Zero-sized tye + +A type is zero-sized (or a "ZST") if its values always have exactly 0 bytes. Such types have only one possible value. Examples include + +* the [unit type][type.tuple.unit] +* [unit-like structs][items.struct.unit] which have no fields +* [unions][items.union] of zero-sized types + +```rust +#[derive(Copy, Clone)] +struct Empty; +union AlwaysEmpty { + f1: (), + f2: Empty, +} +assert_eq!(0, std::mem::size_of::<()>()); +assert_eq!(0, std::mem::size_of::()); +assert_eq!(0, std::mem::size_of::()); +``` + [`extern` blocks]: items.extern [`extern fn`]: items.fn.extern [alignment]: type-layout.md#size-and-alignment