From 39fa8df6318c878f917537dbd48a4ec8be7ac435 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sun, 7 Jun 2026 23:12:59 +0000 Subject: [PATCH] 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. --- src/behavior-considered-undefined.md | 3 ++- src/dynamically-sized-types.md | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/behavior-considered-undefined.md b/src/behavior-considered-undefined.md index 0e3228916d..ef6e889e3a 100644 --- a/src/behavior-considered-undefined.md +++ b/src/behavior-considered-undefined.md @@ -145,7 +145,7 @@ r[undefined.validity.reference-box] * A reference or [`Box`] 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. r[undefined.validity.wide] -* The [metadata] of a wide reference, [`Box`], or raw pointer must match the type of the unsized tail: +* The [metadata] of a wide reference, [`Box`], or raw pointer must match the type of the [unsized tail]: * `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.) * Slice (`[T]`) metadata must be a valid `usize`. Furthermore, for wide references and [`Box`], slice metadata is invalid if it makes the total size of the pointed-to value bigger than `isize::MAX`. @@ -204,6 +204,7 @@ r[undefined.validity.undef] [project-field]: expressions/field-expr.md [project-tuple]: expressions/tuple-expr.md#tuple-indexing-expressions [project-slice]: expressions/array-expr.md#array-and-slice-indexing-expressions +[unsized tail]: dynamic-sized.tail [unwinding-ffi]: panic.md#unwinding-across-ffi-boundaries [const-promoted]: destructors.md#constant-promotion [lifetime-extended]: destructors.md#temporary-lifetime-extension diff --git a/src/dynamically-sized-types.md b/src/dynamically-sized-types.md index 5c9e69a713..b14a807e83 100644 --- a/src/dynamically-sized-types.md +++ b/src/dynamically-sized-types.md @@ -25,10 +25,17 @@ r[dynamic-sized.struct-field] > [!NOTE] > [Variables], function parameters, [const] items, and [static] items must be `Sized`. +r[dynamic-sized.tail] +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. + +[metadata]: dynamic-sized.pointer-types [sized]: special-types-and-traits.md#sized [Slices]: types/slice.md +[slice]: types/slice.md [str]: types/str.md +[`str`]: types/str.md [trait objects]: types/trait-object.md +[trait object]: types/trait-object.md [Pointer types]: types/pointer.md [Variables]: variables.md [const]: items/constant-items.md