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
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,9 +211,65 @@ 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] (see [type.fn-item.intro]).
221
+
- The constructors of [tuple-like structs] (see [type.fn-item.intro]).
222
+
- The constructors of [tuple-like enum variants] (see [type.fn-item.intro]).
223
+
-`repr(C)` structs with no fields ([unit-like structs]) or where all fields are zero-sized (see [layout.repr.c.struct.size-field-offset]).
224
+
-`repr(transparent)` structs with no fields ([unit-like structs]) or where all fields are zero-sized (see [layout.repr.transparent.layout-abi]).
225
+
-[Arrays] of zero-sized types (see [layout.array]).
226
+
-[Arrays] of length zero (see [layout.array]).
227
+
-[Unions] of zero-sized types (see [items.union.common-storage]).
228
+
229
+
```rust
230
+
# usecore::mem::{size_of, size_of_val};
231
+
fnf() {}
232
+
structS(u8);
233
+
enumE { V(u8) }
234
+
#[repr(C)]
235
+
structC1 {}
236
+
#[repr(C)]
237
+
structC2 {
238
+
f1: (),
239
+
f2: [(); 10],
240
+
f3: [u8; 0],
241
+
f4:C1,
242
+
}
243
+
#[repr(transparent)]
244
+
structT1 {}
245
+
#[repr(transparent)]
246
+
structT2 {
247
+
f1: (),
248
+
f2: [(); 10],
249
+
f3: [u8; 0],
250
+
}
251
+
unionU {
252
+
f1: (),
253
+
f2: [(); 10],
254
+
f3: [u8; 0],
255
+
}
256
+
assert_eq!(0, size_of::<()>());
257
+
assert_eq!(0, size_of_val(&f));
258
+
assert_eq!(0, size_of_val(&S));
259
+
assert_eq!(0, size_of_val(&E::V));
260
+
assert_eq!(0, size_of::<C1>());
261
+
assert_eq!(0, size_of::<C2>());
262
+
assert_eq!(0, size_of::<T1>());
263
+
assert_eq!(0, size_of::<T2>());
264
+
assert_eq!(0, size_of::<[(); 10]>());
265
+
assert_eq!(0, size_of::<[u8; 0]>());
266
+
assert_eq!(0, size_of::<U>());
267
+
```
268
+
214
269
[`extern` blocks]: items.extern
215
270
[`extern fn`]: items.fn.extern
216
271
[alignment]: type-layout.md#size-and-alignment
272
+
[arrays]: type.array
217
273
[associated item]: #associated-item
218
274
[attributes]: attributes.md
219
275
[*entity*]: names.md
@@ -222,6 +278,7 @@ A type is uninhabited if it has no constructors and therefore can never be insta
222
278
[enums]: items/enumerations.md
223
279
[fields]: expressions/field-expr.md
224
280
[free item]: #free-item
281
+
[function items]: type.fn-item
225
282
[generic parameters]: items/generics.md
226
283
[identifier]: identifiers.md
227
284
[identifiers]: identifiers.md
@@ -245,12 +302,16 @@ A type is uninhabited if it has no constructors and therefore can never be insta
0 commit comments