Skip to content

Commit 3139bd7

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 a7c967f commit 3139bd7

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
@@ -388,7 +388,8 @@ reference types and `mut` or `const` in pointer types.
388388
\* or `T` and `V` are unsized types with compatible metadata:
389389
* both slice metadata (`*[u16]` -> `*[u8]`, `*str` -> `*(u8, [u32])`).
390390
* both the same trait object metadata, modulo dropping auto traits (`*dyn Debug` -> `*(u16, dyn Debug)`, `*dyn Debug + Send` -> `*dyn Debug`).
391-
* **Note**: *adding* auto traits is not allowed (`*dyn Debug` -> `*dyn Debug + Send` is invalid).
391+
* **Note**: *adding* auto traits is only allowed if the principal trait has the auto trait as a super trait
392+
(given `trait T: Send {}`, `*dyn T` -> `*dyn T + Send` is valid, but `*dyn Debug` -> `*dyn Debug + Send` is not).
392393
* **Note**: generics (including lifetimes) must match (`*dyn T<'a, A>` -> `*dyn T<'b, B>` requires `'a = 'b` and `A = B`).
393394

394395
\*\* 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
@@ -219,6 +219,8 @@ r[coerce.unsize.trait-upcast]
219219
* `dyn T` to `dyn U`, when `U` is one of `T`'s supertraits.
220220
* `dyn T` to `dyn U` when `U` is one of `T`'s [supertraits].
221221
* This allows dropping auto traits, i.e. `dyn T + Auto` to `dyn U` is allowed.
222+
* This allows adding auto traits if the principal trait has the auto trait as a super trait,
223+
i.e. given `trait T: U + Send {}`, `dyn T` to `dyn T + Send` or to `dyn U + Send` coercions are allowed.
222224

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

0 commit comments

Comments
 (0)