Skip to content

Commit 0a2d4d0

Browse files
committed
Mention that you can add auto traits if principal has them as supers
i.e. document the behavior after r-l/r/119338
1 parent 4949a09 commit 0a2d4d0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/expressions/operator-expr.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ reference types and `mut` or `const` in pointer types.
475475
\* or `T` and `V` are unsized types with compatible metadata:
476476
* both slice metadata (`*[u16]` -> `*[u8]`, `*str` -> `*(u8, [u32])`).
477477
* both the same trait object metadata, modulo dropping auto traits (`*dyn Debug` -> `*(u16, dyn Debug)`, `*dyn Debug + Send` -> `*dyn Debug`).
478-
* **Note**: *adding* auto traits is not allowed (`*dyn Debug` -> `*dyn Debug + Send` is invalid).
478+
* **Note**: *adding* auto traits is only allowed if the principal trait has the auto trait as a super trait
479+
(given `trait T: Send {}`, `*dyn T` -> `*dyn T + Send` is valid, but `*dyn Debug` -> `*dyn Debug + Send` is not).
479480
* **Note**: generics (including lifetimes) must match (`*dyn T<'a, A>` -> `*dyn T<'b, B>` requires `'a = 'b` and `A = B`).
480481

481482
\*\* only when `m₁` is `mut` or `m₂` is `const`. Casting `mut` reference to

src/type-coercions.md

+2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ r[coerce.unsize.trait-object]
214214
r[coerce.unsize.trait-upcast]
215215
* `dyn T` to `dyn U`, when `U` is one of `T`'s [supertraits].
216216
* This allows dropping auto traits, i.e. `dyn T + Auto` to `dyn U` is allowed.
217+
* This allows adding auto traits if the principal trait has the auto trait as a super trait,
218+
i.e. given `trait T: U + Send {}`, `dyn T` to `dyn T + Send` or to `dyn U + Send` coercions are allowed.
217219

218220
r[coerce.unsized.composite]
219221
* `Foo<..., T, ...>` to `Foo<..., U, ...>`, when:

0 commit comments

Comments
 (0)