diff --git a/src/glossary.md b/src/glossary.md index 9d39173e01..9ad96a92a1 100644 --- a/src/glossary.md +++ b/src/glossary.md @@ -211,9 +211,33 @@ 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 type (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]). +- [Arrays] of zero-sized types (see [layout.array]). +- [Arrays] of length zero (see [layout.array]). +- [Unions] of zero-sized types (see [items.union.common-storage]). + +```rust +# use core::mem::size_of; +union U { + f1: (), + f2: [(); 10], + f3: [u8; 0], +} +assert_eq!(0, size_of::<()>()); +assert_eq!(0, size_of::<[(); 10]>()); +assert_eq!(0, size_of::<[u8; 0]>()); +assert_eq!(0, size_of::()); +``` + [`extern` blocks]: items.extern [`extern fn`]: items.fn.extern [alignment]: type-layout.md#size-and-alignment +[arrays]: type.array [associated item]: #associated-item [attributes]: attributes.md [*entity*]: names.md @@ -252,5 +276,6 @@ A type is uninhabited if it has no constructors and therefore can never be insta [types]: types.md [undefined-behavior]: behavior-considered-undefined.md [unions]: items/unions.md +[unit type]: type.tuple.unit [variable bindings]: patterns.md [visibility rules]: visibility-and-privacy.md