Skip to content

Commit dc4cf65

Browse files
Add backlinks to glossary.zst
1 parent 93776bb commit dc4cf65

6 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/behavior-considered-undefined.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ A reference/pointer is "dangling" if not all of the bytes it
139139
part of *some* allocation).
140140

141141
r[undefined.dangling.zero-size]
142-
If the size is 0, then the pointer is trivially never "dangling"
142+
If the [size is 0][zero-sized], then the pointer is trivially never "dangling"
143143
(even if it is a null pointer).
144144

145145
r[undefined.dangling.dynamic-size]
@@ -189,7 +189,7 @@ r[undefined.validity.struct]
189189
r[undefined.validity.union]
190190
* For a `union`, the exact validity requirements are not decided yet.
191191
Obviously, all values that can be created entirely in safe code are valid.
192-
If the union has a zero-sized field, then every possible value is valid.
192+
If the union has a [zero-sized] field, then every possible value is valid.
193193
Further details are [still being debated](https://github.com/rust-lang/unsafe-code-guidelines/issues/438).
194194

195195
r[undefined.validity.reference-box]
@@ -268,3 +268,4 @@ reading uninitialized memory is permitted are inside `union`s and in "padding"
268268
[unwinding-ffi]: panic.md#unwinding-across-ffi-boundaries
269269
[const-promoted]: destructors.md#constant-promotion
270270
[lifetime-extended]: destructors.md#temporary-lifetime-extension
271+
[zero-sized]: glossary.zst

src/items/functions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ r[items.fn.implicit-return]
5353
If the output type is not explicitly stated, it is the [unit type].
5454

5555
r[items.fn.fn-item-type]
56-
When referred to, a _function_ yields a first-class *value* of the corresponding zero-sized [*function item type*], which when called evaluates to a direct call to the function.
56+
When referred to, a _function_ yields a first-class *value* of the corresponding [zero-sized] [*function item type*], which when called evaluates to a direct call to the function.
5757

5858
For example, this is a simple function:
5959

@@ -426,3 +426,4 @@ fn foo_oof(#[some_inert_attribute] arg: u8) {
426426
[value namespace]: ../names/namespaces.md
427427
[variadic function]: external-blocks.md#variadic-functions
428428
[`extern` block]: external-blocks.md
429+
[zero-sized]: glossary.zst

src/special-types-and-traits.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mutability aren't placed in memory marked as read only.
5959
r[lang-types.phantom-data]
6060
## `PhantomData<T>`
6161

62-
[`std::marker::PhantomData<T>`] is a zero-sized, minimum alignment, type that
62+
[`std::marker::PhantomData<T>`] is a [zero-sized], minimum alignment, type that
6363
is considered to own a `T` for the purposes of [variance], [drop check], and
6464
[auto traits](#auto-traits).
6565

@@ -246,6 +246,7 @@ These implicit `Sized` bounds may be relaxed by using the special `?Sized` bound
246246
[test functions]: attributes/testing.md#the-test-attribute
247247
[the standard library]: std
248248
[trait object]: types/trait-object.md
249+
[zero-sized]: glossary.zst
249250
[Tuples]: types/tuple.md
250251
[Type parameters]: types/parameters.md
251252
[variance]: subtyping.md#variance

src/type-layout.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ r[layout.properties.align]
1818
The *alignment* of a value specifies what addresses are valid to store the value at. A value of alignment `n` must only be stored at an address that is a multiple of n. For example, a value with an alignment of 2 must be stored at an even address, while a value with an alignment of 1 can be stored at any address. Alignment is measured in bytes, and must be at least 1, and always a power of 2. The alignment of a value can be checked with the [`align_of_val`] function.
1919

2020
r[layout.properties.size]
21-
The *size* of a value is the offset in bytes between successive elements in an array with that item type including alignment padding. The size of a value is always a multiple of its alignment. Note that some types are zero-sized; 0 is considered a multiple of any alignment (for example, on some platforms, the type `[u16; 0]` has size 0 and alignment 2). The size of a value can be checked with the [`size_of_val`] function.
21+
The *size* of a value is the offset in bytes between successive elements in an array with that item type including alignment padding. The size of a value is always a multiple of its alignment. Note that some types are [zero-sized]; 0 is considered a multiple of any alignment (for example, on some platforms, the type `[u16; 0]` has size 0 and alignment 2). The size of a value can be checked with the [`size_of_val`] function.
2222

2323
r[layout.properties.sized]
2424
Types where all values have the same size and alignment, and both are known at compile time, implement the [`Sized`] trait and can be checked with the [`size_of`] and [`align_of`] functions. Types that are not [`Sized`] are known as [dynamically sized types]. Since all values of a `Sized` type share the same size and alignment, we refer to those shared values as the size of the type and the alignment of the type respectively.
@@ -94,7 +94,7 @@ r[layout.tuple.def]
9494
Tuples are laid out according to the [`Rust` representation][`Rust`].
9595

9696
r[layout.tuple.unit]
97-
The exception to this is the unit tuple (`()`), which is guaranteed as a zero-sized type to have a size of 0 and an alignment of 1.
97+
The exception to this is the unit tuple (`()`), which is guaranteed as a [zero-sized type] to have a size of 0 and an alignment of 1.
9898

9999
r[layout.trait-object]
100100
## Trait object layout
@@ -178,7 +178,7 @@ The only data layout guarantees made by this representation are those required f
178178
r[layout.repr.rust.layout.struct]
179179
For [structs], it is further guaranteed that the fields do not overlap. That is, the fields can be ordered such that the offset plus the size of any field is less than or equal to the offset of the next field in the ordering. The ordering does not have to be the same as the order in which the fields are specified in the declaration of the type.
180180

181-
Be aware that this guarantee does not imply that the fields have distinct addresses: zero-sized types may have the same address as other fields in the same struct.
181+
Be aware that this guarantee does not imply that the fields have distinct addresses: [zero-sized types] may have the same address as other fields in the same struct.
182182

183183
r[layout.repr.rust.unspecified]
184184
There are no other guarantees of data layout made by this representation.
@@ -248,7 +248,7 @@ struct.size = current_offset + padding_needed_for(current_offset, struct.alignme
248248
> This pseudocode uses a naive algorithm that ignores overflow issues for the sake of clarity. To perform memory layout computations in actual code, use [`Layout`].
249249
250250
> [!NOTE]
251-
> This algorithm can produce zero-sized structs. In C, an empty struct declaration like `struct Foo { }` is illegal. However, both gcc and clang support options to enable such structs, and assign them size zero. C++, in contrast, gives empty structs a size of 1, unless they are inherited from or they are fields that have the `[[no_unique_address]]` attribute, in which case they do not increase the overall size of the struct.
251+
> This algorithm can produce [zero-sized structs]. In C, an empty struct declaration like `struct Foo { }` is illegal. However, both gcc and clang support options to enable such structs, and assign them size zero. C++, in contrast, gives empty structs a size of 1, unless they are inherited from or they are fields that have the `[[no_unique_address]]` attribute, in which case they do not increase the overall size of the struct.
252252
253253
r[layout.repr.c.union]
254254
#### `#[repr(C)]` Unions
@@ -561,6 +561,10 @@ Because this representation delegates type layout to another type, it cannot be
561561
[enumerations]: items/enumerations.md
562562
[zero-variant enums]: items/enumerations.md#zero-variant-enums
563563
[undefined behavior]: behavior-considered-undefined.md
564+
[zero-sized]: glossary.zst
565+
[zero-sized type]: glossary.zst
566+
[zero-sized types]: glossary.zst
567+
[zero-sized structs]: glossary.zst
564568
[`PhantomData<T>`]: special-types-and-traits.md#phantomdatat
565569
[`Rust`]: #the-rust-representation
566570
[`C`]: #the-c-representation

src/types/function-item.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ r[type.fn-item]
22
# Function item types
33

44
r[type.fn-item.intro]
5-
When referred to, a function item, or the constructor of a tuple-like struct or enum variant, yields a zero-sized value of its _function item type_.
5+
When referred to, a function item, or the constructor of a tuple-like struct or enum variant, yields a [zero-sized] value of its _function item type_.
66

77
r[type.fn-item.unique]
88
That type explicitly identifies the function - its name, its type arguments, and its early-bound lifetime arguments (but not its late-bound lifetime arguments, which are only assigned when the function is called) - so the value does not need to contain an actual function pointer, and no indirection is needed when the function is called.
@@ -51,3 +51,4 @@ All function items implement [`Copy`], [`Clone`], [`Send`], and [`Sync`].
5151
[`Sync`]: ../special-types-and-traits.md#sync
5252
[coercion]: ../type-coercions.md
5353
[function pointers]: function-pointer.md
54+
[zero-sized]: glossary.zst

src/types/pointer.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ r[type.pointer.validity.pointer-fragment]
7070
Despite pointers and references being similar to `usize`s in the machine code emitted on most platforms, the semantics of transmuting a reference or pointer type to a non-pointer type is currently undecided. Thus, it may not be valid to transmute a pointer or reference type, `P`, to a `[u8; size_of::<P>()]`.
7171

7272
r[type.pointer.validity.raw]
73-
For thin raw pointers (i.e., for `P = *const T` or `P = *mut T` for `T: Sized`), the inverse direction (transmuting from an integer or array of integers to `P`) is always valid. However, the pointer produced via such a transmutation may not be dereferenced (not even if `T` has size zero).
73+
For thin raw pointers (i.e., for `P = *const T` or `P = *mut T` for `T: Sized`), the inverse direction (transmuting from an integer or array of integers to `P`) is always valid. However, the pointer produced via such a transmutation may not be dereferenced (not even if `T` has [size zero]).
7474

7575
[Interior mutability]: ../interior-mutability.md
7676
[`unsafe` operation]: ../unsafety.md
7777
[dynamically sized types]: ../dynamically-sized-types.md
78+
[size zero]: glossary.zst
7879
[temporary value]: ../expressions.md#temporaries

0 commit comments

Comments
 (0)