From 3139bd704b89e8d1dace367f5f44d4355fda293b Mon Sep 17 00:00:00 2001 From: Maybe Lapkin Date: Sat, 21 Sep 2024 11:22:32 +0200 Subject: [PATCH] Mention that you can add auto traits if principal has them as supers i.e. document the behavior after r-l/r/119338 --- src/expressions/operator-expr.md | 3 ++- src/type-coercions.md | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/expressions/operator-expr.md b/src/expressions/operator-expr.md index 383086a78..09ff8ed49 100644 --- a/src/expressions/operator-expr.md +++ b/src/expressions/operator-expr.md @@ -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 diff --git a/src/type-coercions.md b/src/type-coercions.md index e1f7dabe5..e854d20a8 100644 --- a/src/type-coercions.md +++ b/src/type-coercions.md @@ -219,6 +219,8 @@ r[coerce.unsize.trait-upcast] * `dyn T` to `dyn U`, when `U` is one of `T`'s supertraits. * `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. r[coerce.unsized.composite] * `Foo<..., T, ...>` to `Foo<..., U, ...>`, when: