Skip to content

Commit

Permalink
Mention that you can add auto traits if principal has them as supers
Browse files Browse the repository at this point in the history
i.e. document the behavior after r-l/r/119338
  • Loading branch information
WaffleLapkin committed Sep 21, 2024
1 parent f021dfe commit 607255c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/expressions/operator-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ reference types and `mut` or `const` in pointer types.
\* or `T` and `V` are unsized types with compatible metadata:
* both slice metadata (`*[u16]` -> `*[u8]`, `*str` -> `*(u8, [u32])`).
* both the same trait object metadata, modulo dropping auto traits (`*dyn Debug` -> `*(u16, dyn Debug)`, `*dyn Debug + Send` -> `*dyn Debug`).
* **Note**: *adding* auto traits is not allowed (`*dyn Debug` -> `*dyn Debug + Send` is invalid).
* **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).
* **Note**: generics (including lifetimes) must match (`*dyn T<'a, A>` -> `*dyn T<'b, B>` requires `'a = 'b` and `A = B`).

\*\* only when `m₁` is `mut` or `m₂` is `const`. Casting `mut` reference to
Expand Down
2 changes: 2 additions & 0 deletions src/type-coercions.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ an implementation of `Unsize<U>` for `T` will be provided:

* `dyn T` to `dyn U` when `U` is one of `T`'s [supertraits].
* This allows dropping auto traits, i.e. `dyn T + Auto` to `dyn U` is allowed.
* 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.

* `Foo<..., T, ...>` to `Foo<..., U, ...>`, when:
* `Foo` is a struct.
Expand Down

0 comments on commit 607255c

Please sign in to comment.