Skip to content

Commit 39fa8df

Browse files
committed
Define an unsized tail
We refer to the unsized tail of a type, but we hadn't defined it. Let's do that and link to the definition.
1 parent e9ebd56 commit 39fa8df

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/behavior-considered-undefined.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ r[undefined.validity.reference-box]
145145
* A reference or [`Box<T>`] must be aligned and non-null, it cannot be [dangling], and it must point to a valid value (in case of dynamically sized types, using the actual dynamic type of the pointee as determined by the [metadata]). Note that the last point (about pointing to a valid value) remains a subject of some debate.
146146

147147
r[undefined.validity.wide]
148-
* The [metadata] of a wide reference, [`Box<T>`], or raw pointer must match the type of the unsized tail:
148+
* The [metadata] of a wide reference, [`Box<T>`], or raw pointer must match the type of the [unsized tail]:
149149
* `dyn Trait` metadata must be a pointer to a compiler-generated vtable for `Trait`. (For raw pointers, this requirement remains a subject of some debate.)
150150
* Slice (`[T]`) metadata must be a valid `usize`. Furthermore, for wide references and [`Box<T>`], slice metadata is invalid if it makes the total size of the pointed-to value bigger than `isize::MAX`.
151151

@@ -204,6 +204,7 @@ r[undefined.validity.undef]
204204
[project-field]: expressions/field-expr.md
205205
[project-tuple]: expressions/tuple-expr.md#tuple-indexing-expressions
206206
[project-slice]: expressions/array-expr.md#array-and-slice-indexing-expressions
207+
[unsized tail]: dynamic-sized.tail
207208
[unwinding-ffi]: panic.md#unwinding-across-ffi-boundaries
208209
[const-promoted]: destructors.md#constant-promotion
209210
[lifetime-extended]: destructors.md#temporary-lifetime-extension

src/dynamically-sized-types.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ r[dynamic-sized.struct-field]
2525
> [!NOTE]
2626
> [Variables], function parameters, [const] items, and [static] items must be `Sized`.
2727
28+
r[dynamic-sized.tail]
29+
The *unsized tail* of a type is the dynamically sized component that the [metadata] of a pointer to the type describes. A [slice] (`[T]`) and a [`str`] are each their own unsized tail, described by a length; a [trait object] (`dyn Trait`) is its own unsized tail, described by a pointer to a vtable. When a struct (per [dynamic-sized.struct-field]) or a tuple has an unsized last field, its unsized tail is the unsized tail of that field. A sized type has no unsized tail.
30+
31+
[metadata]: dynamic-sized.pointer-types
2832
[sized]: special-types-and-traits.md#sized
2933
[Slices]: types/slice.md
34+
[slice]: types/slice.md
3035
[str]: types/str.md
36+
[`str`]: types/str.md
3137
[trait objects]: types/trait-object.md
38+
[trait object]: types/trait-object.md
3239
[Pointer types]: types/pointer.md
3340
[Variables]: variables.md
3441
[const]: items/constant-items.md

0 commit comments

Comments
 (0)