Skip to content

Commit 27212ee

Browse files
Glossary: add new entry documenting zero-sized types
1 parent 3199c6a commit 27212ee

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/glossary.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ r[glossary.uninhabited]
211211

212212
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).
213213

214+
r[glossary.zst]
215+
### Zero-sized type
216+
217+
A type is zero-sized (or a "ZST") if its size is 0. Such types have only one possible value. Examples include
218+
219+
- The [unit type][type.tuple.unit].
220+
- [Unit-like structs][items.struct.unit] which have no fields.
221+
- [Unions][items.union] of zero-sized types.
222+
223+
```rust
224+
#[derive(Copy, Clone)]
225+
struct Empty;
226+
union AlwaysEmpty {
227+
f1: (),
228+
f2: Empty,
229+
}
230+
assert_eq!(0, std::mem::size_of::<()>());
231+
assert_eq!(0, std::mem::size_of::<Empty>());
232+
assert_eq!(0, std::mem::size_of::<AlwaysEmpty>());
233+
```
234+
214235
[`extern` blocks]: items.extern
215236
[`extern fn`]: items.fn.extern
216237
[alignment]: type-layout.md#size-and-alignment

0 commit comments

Comments
 (0)