Skip to content

Commit

Permalink
Add information about casting pointers to unsized types
Browse files Browse the repository at this point in the history
This aligns the reference with the results of r-l/r/120248.
  • Loading branch information
WaffleLapkin committed Sep 20, 2024
1 parent e7c2fa0 commit d07f7f0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/expressions/operator-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d07f7f0

Please sign in to comment.