@@ -313,18 +313,18 @@ field which it contains; in the case of `Option<T>`, the payload has
313
313
type `T`.
314
314
315
315
**Definition.** In some cases, the payload type may contain illegal
316
- values, which are called **niches**. For example, a value of type `&T`
317
- may never be `NULL`, and hence defines a niche consisting of the
316
+ values, which are called **[ niches][niche] **. For example, a value of type `&T`
317
+ may never be `NULL`, and hence defines a [ niche] consisting of the
318
318
bitstring `0`. Similarly, the standard library types [`NonZeroU8`]
319
319
and friends may never be zero, and hence also define the value of `0`
320
- as a niche.
320
+ as a [ niche] .
321
321
322
322
[`NonZeroU8`]: https://doc.rust-lang.org/std/num/struct.NonZeroU8.html
323
323
324
- The niche values must be disjoint from the values allowed by the validity
324
+ The [ niche] values must be disjoint from the values allowed by the validity
325
325
invariant. The validity invariant is, as of this writing, the current active
326
326
discussion topic in the unsafe code guidelines process. [rust-lang/rust#60300]
327
- specifies that the following types have at least one niche (the all-zeros
327
+ specifies that the following types have at least one [ niche] (the all-zeros
328
328
bit-pattern):
329
329
330
330
* `&T`
@@ -334,15 +334,15 @@ bit-pattern):
334
334
* `core::ptr::NonNull<T>`
335
335
* `#[repr(transparent)] struct` around one of the types in this list.
336
336
337
- **Option-like enums where the payload defines at least one niche value
337
+ **Option-like enums where the payload defines at least one [ niche] value
338
338
are guaranteed to be represented using the same memory layout as their
339
339
payload.** This is called **discriminant elision**, as there is no
340
- explicit discriminant value stored anywhere. Instead, niche values are
340
+ explicit discriminant value stored anywhere. Instead, [ niche] values are
341
341
used to represent the unit variant.
342
342
343
343
The most common example is that `Option<&u8>` can be represented as an
344
344
nullable `&u8` reference -- the `None` variant is then represented
345
- using the niche value zero. This is because a valid `&u8` value can
345
+ using the [ niche] value zero. This is because a valid `&u8` value can
346
346
never be zero, so if we see a zero value, we know that this must be
347
347
`None` variant.
348
348
@@ -376,6 +376,8 @@ enum Enum2<T> {
376
376
}
377
377
```
378
378
379
+ [niche]: ../glossary.html#niche
380
+
379
381
## Unresolved questions
380
382
381
383
### Layout of single variant enums
0 commit comments