You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/glossary.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,9 +211,35 @@ r[glossary.uninhabited]
211
211
212
212
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).
213
213
214
+
r[glossary.zst]
215
+
### Zero-sized type (ZST)
216
+
217
+
A type is zero sized (a ZST) if its size is 0. Such types have at most one possible value. Examples include:
218
+
219
+
- The [unit type] (see [layout.tuple.unit]).
220
+
-[Function items], or the constructors of a tuple-like structs or enum variants (see [type.fn-item.intro])
221
+
-[Arrays] of zero-sized types (see [layout.array]).
222
+
-[Arrays] of length zero (see [layout.array]).
223
+
-[Unions] of zero-sized types (see [items.union.common-storage]).
224
+
225
+
```rust
226
+
# usecore::mem::{size_of, size_of_val};
227
+
unionU {
228
+
f1: (),
229
+
f2: [(); 10],
230
+
f3: [u8; 0],
231
+
}
232
+
assert_eq!(0, size_of::<()>());
233
+
assert_eq!(0, size_of_val(&main));
234
+
assert_eq!(0, size_of::<[(); 10]>());
235
+
assert_eq!(0, size_of::<[u8; 0]>());
236
+
assert_eq!(0, size_of::<U>());
237
+
```
238
+
214
239
[`extern` blocks]: items.extern
215
240
[`extern fn`]: items.fn.extern
216
241
[alignment]: type-layout.md#size-and-alignment
242
+
[arrays]: type.array
217
243
[associated item]: #associated-item
218
244
[attributes]: attributes.md
219
245
[*entity*]: names.md
@@ -222,6 +248,7 @@ A type is uninhabited if it has no constructors and therefore can never be insta
222
248
[enums]: items/enumerations.md
223
249
[fields]: expressions/field-expr.md
224
250
[free item]: #free-item
251
+
[function items]: type.fn-item
225
252
[generic parameters]: items/generics.md
226
253
[identifier]: identifiers.md
227
254
[identifiers]: identifiers.md
@@ -252,5 +279,6 @@ A type is uninhabited if it has no constructors and therefore can never be insta
0 commit comments