Skip to content

Commit 62a9187

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

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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 tye
216+
217+
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
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)