diff --git a/src/glossary.md b/src/glossary.md index 9d39173e01..694ed95a72 100644 --- a/src/glossary.md +++ b/src/glossary.md @@ -211,9 +211,30 @@ 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 only one possible value. Examples include: + +- The [unit type] (see [layout.tuple.unit]). +- [Arrays] of zero-sized types (see [layout.array]). +- [Unions] of zero-sized types (see [items.union.common-storage]). + +```rust +# use core::mem::size_of; +union U { + f1: (), + f2: [(); 10], +} +assert_eq!(0, size_of::<()>()); +assert_eq!(0, size_of::<[(); 10]>()); +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 +273,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