Skip to content

Commit 2837b28

Browse files
WaffleLapkintraviscross
authored andcommitted
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 97b4810 commit 2837b28

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/expressions/operator-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ reference types and `mut` or `const` in pointer types.
476476

477477
* Both slice metadata (`*[u16]` -> `*[u8]`, `*str` -> `*(u8, [u32])`).
478478
* Both the same trait object metadata, modulo dropping auto traits (`*dyn Debug` -> `*(u16, dyn Debug)`, `*dyn Debug + Send` -> `*dyn Debug`).
479-
* **Note**: Adding auto traits is not allowed (`*dyn Debug` -> `*dyn Debug + Send` is invalid).
479+
* **Note**: Adding auto traits is only allowed if the principal trait has the auto trait as a super trait (given `trait T: Send {}`, `*dyn T` -> `*dyn T + Send` is valid, but `*dyn Debug` -> `*dyn Debug + Send` is not).
480480
* **Note**: Generics (including lifetimes) must match (`*dyn T<'a, A>` -> `*dyn T<'b, B>` requires `'a = 'b` and `A = B`).
481481

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

src/type-coercions.md

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ r[coerce.unsize.trait-object]
210210
r[coerce.unsize.trait-upcast]
211211
* `dyn T` to `dyn U`, when `U` is one of `T`'s [supertraits].
212212
* This allows dropping auto traits, i.e. `dyn T + Auto` to `dyn U` is allowed.
213+
* This allows adding auto traits if the principal trait has the auto trait as a super trait, i.e. given `trait T: U + Send {}`, `dyn T` to `dyn T + Send` or to `dyn U + Send` coercions are allowed.
213214

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

0 commit comments

Comments
 (0)