Define an unsized tail#2287
Conversation
We refer to the unsized tail of a type, but we hadn't defined it. Let's do that and link to the definition.
e3cc399 to
39fa8df
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| > [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. |
There was a problem hiding this comment.
This definition contains redundant information with the definition of "metadata" from #2286. That doesn't seem great, we should define these things only in one place and then reference them elsewhere.
There was a problem hiding this comment.
Agreed. I had the same thought. I didn't have any immediate good ideas for how to resolve it, though (other than ensuring they were cross-linked, as I did). Suggestions welcome.
There was a problem hiding this comment.
We could define "unsized tail" without repeating the metadata definition. For instance:
The unsized tail of an unsized type is the unsized type at the "end" of the type, after recursing through compound types:
- A [slice] (
[T]), a [str], and a [trait object] (dyn Trait) are each their own unsized tail. - 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.
And then for metadata I'd say something like:
[Pointer types] to DSTs are sized but have twice the size of pointers to sized types, since they also store metadata.
The metadata carries by a pointer is determined by the [unsized tail] of its pointee type:
- If the unsized tail is a slice or
str, ... - If the unsized tail is a trait object, ...
Update books ## rust-lang/nomicon 1 commits in cc6a6bae8c3bfa389974e533c54694662c1a9de6..5012a37c682b26c4e19433888ed2ca9b129696ca 2026-06-25 10:05:58 UTC to 2026-06-25 10:05:58 UTC - Clarify when safety may rely on correctness (rust-lang/nomicon#523) ## rust-lang/reference 10 commits in 2c27905c15a51983b54d84f050d3bda096194d27..86635e30bf861a038dc197d7e16fd09e7e514e7a 2026-06-25 17:00:32 UTC to 2026-06-16 18:56:35 UTC - use-declarations.md: move example to where it's described (rust-lang/reference#2295) - fix link target (rust-lang/reference#2299) - remove broken text (rust-lang/reference#2297) - type-layout: rewrite `#[repr(C)]` struct layout algorithm (rust-lang/reference#2243) - Fix grammar rules containing or pertaining to bounds (rust-lang/reference#2257) - Document metadata of ptrs to indirectly unsized types (rust-lang/reference#2289) - Generalize the wide-pointer total-size bound (rust-lang/reference#2290) - Cover `str` in the wide-pointer metadata rule (rust-lang/reference#2288) - Define an unsized tail (rust-lang/reference#2287) - Define pointer metadata (rust-lang/reference#2286)
Rollup merge of #158571 - rustbot:docs-update, r=ehuss Update books ## rust-lang/nomicon 1 commits in cc6a6bae8c3bfa389974e533c54694662c1a9de6..5012a37c682b26c4e19433888ed2ca9b129696ca 2026-06-25 10:05:58 UTC to 2026-06-25 10:05:58 UTC - Clarify when safety may rely on correctness (rust-lang/nomicon#523) ## rust-lang/reference 10 commits in 2c27905c15a51983b54d84f050d3bda096194d27..86635e30bf861a038dc197d7e16fd09e7e514e7a 2026-06-25 17:00:32 UTC to 2026-06-16 18:56:35 UTC - use-declarations.md: move example to where it's described (rust-lang/reference#2295) - fix link target (rust-lang/reference#2299) - remove broken text (rust-lang/reference#2297) - type-layout: rewrite `#[repr(C)]` struct layout algorithm (rust-lang/reference#2243) - Fix grammar rules containing or pertaining to bounds (rust-lang/reference#2257) - Document metadata of ptrs to indirectly unsized types (rust-lang/reference#2289) - Generalize the wide-pointer total-size bound (rust-lang/reference#2290) - Cover `str` in the wide-pointer metadata rule (rust-lang/reference#2288) - Define an unsized tail (rust-lang/reference#2287) - Define pointer metadata (rust-lang/reference#2286)
We refer to the unsized tail of a type, but we hadn't defined it. Let's do that and link to the definition.
I'm breaking this out from #2282 so that we can merge the prerequisites before considering the new lang guarantees.
This is stacked on #2286 and that should be merged first.
cc @ehuss @RalfJung @Mark-Simulacrum