Skip to content

Commit cd32837

Browse files
authored
Rollup merge of rust-lang#117495 - compiler-errors:unsize-docs, r=lcnr
Clarify `Unsize` documentation The documentation erroneously says that: ```rust /// - Types implementing a trait `Trait` also implement `Unsize<dyn Trait>`. /// - Structs `Foo<..., T, ...>` implement `Unsize<Foo<..., U, ...>>` if all of these conditions /// are met: /// - `T: Unsize<U>`. /// - Only the last field of `Foo` has a type involving `T`. /// - `Bar<T>: Unsize<Bar<U>>`, where `Bar<T>` stands for the actual type of that last field. ``` Specifically, `T: Unsize<U>` is not required to hold -- only the final field must implement `FinalField<T>: Unsize<FinalField<U>>`. This can be demonstrated by the test I added. --- Second commit fleshes out the documentation a lot more.
2 parents 82d3441 + cf4f2e0 commit cd32837

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

core/src/marker.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,18 @@ pub trait Sized {
155155
/// Those implementations are:
156156
///
157157
/// - Arrays `[T; N]` implement `Unsize<[T]>`.
158-
/// - Types implementing a trait `Trait` also implement `Unsize<dyn Trait>`.
159-
/// - Structs `Foo<..., T, ...>` implement `Unsize<Foo<..., U, ...>>` if all of these conditions
160-
/// are met:
161-
/// - `T: Unsize<U>`.
162-
/// - Only the last field of `Foo` has a type involving `T`.
163-
/// - `Bar<T>: Unsize<Bar<U>>`, where `Bar<T>` stands for the actual type of that last field.
158+
/// - A type implements `Unsize<dyn Trait + 'a>` if all of these conditions are met:
159+
/// - The type implements `Trait`.
160+
/// - `Trait` is object safe.
161+
/// - The type is sized.
162+
/// - The type outlives `'a`.
163+
/// - Structs `Foo<..., T1, ..., Tn, ...>` implement `Unsize<Foo<..., U1, ..., Un, ...>>`
164+
/// where any number of (type and const) parameters may be changed if all of these conditions
165+
/// are met:
166+
/// - Only the last field of `Foo` has a type involving the parameters `T1`, ..., `Tn`.
167+
/// - All other parameters of the struct are equal.
168+
/// - `Field<T1, ..., Tn>: Unsize<Field<U1, ..., Un>>`, where `Field<...>` stands for the actual
169+
/// type of the struct's last field.
164170
///
165171
/// `Unsize` is used along with [`ops::CoerceUnsized`] to allow
166172
/// "user-defined" containers such as [`Rc`] to contain dynamically-sized

0 commit comments

Comments
 (0)