Skip to content
Open
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
25 changes: 25 additions & 0 deletions src/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Comment thread
DanielEScherzer marked this conversation as resolved.
- [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::<U>());
```

[`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
Expand Down Expand Up @@ -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
Loading