Skip to content

Commit 7451a0e

Browse files
committed
Add information about casting pointers to unsized types
This aligns the reference with the results of r-l/r/120248.
1 parent 5e57afc commit 7451a0e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/expressions/operator-expr.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,11 @@ reference types and `mut` or `const` in pointer types.
385385
| [Function pointer] | Integer | Function pointer to address cast |
386386
| Closure \*\*\* | Function pointer | Closure to function pointer cast |
387387

388-
\* or `T` and `V` are compatible unsized types, e.g., both slices, both the same trait object.
388+
\* or `T` and `V` are unsized types with compatible metadata:
389+
* both slice metadata (`*[u16]` -> `*[u8]`, `*str` -> `*(u8, [u32])`).
390+
* 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).
392+
* **Note**: generics (including lifetimes) must match (`*dyn T<'a, A>` -> `*dyn T<'b, B>` requires `'a = 'b` and `A = B`).
389393

390394
\*\* only when `m₁` is `mut` or `m₂` is `const`. Casting `mut` reference to
391395
`const` pointer is allowed.

0 commit comments

Comments
 (0)