From d07f7f02b0739b338d2e2dbb7c363189a8da988a Mon Sep 17 00:00:00 2001 From: Maybe Lapkin Date: Fri, 20 Sep 2024 10:33:24 +0200 Subject: [PATCH] Add information about casting pointers to unsized types This aligns the reference with the results of r-l/r/120248. --- src/expressions/operator-expr.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/expressions/operator-expr.md b/src/expressions/operator-expr.md index a9e91f0a6..3d7319d7e 100644 --- a/src/expressions/operator-expr.md +++ b/src/expressions/operator-expr.md @@ -385,7 +385,11 @@ reference types and `mut` or `const` in pointer types. | [Function pointer] | Integer | Function pointer to address cast | | Closure \*\*\* | Function pointer | Closure to function pointer cast | -\* or `T` and `V` are compatible unsized types, e.g., both slices, both the same trait object. +\* 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**: 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 `const` pointer is allowed.