reference
reference copied to clipboard
Clarify semantics of the various pointer to pointer casts
Relates #1448
I've tried to the best of my ability to reproduce the verbiage of the reference, some parts feel a bit wordy to me so any feedback would be appreciated.
To fully describe the semantics of unsized to sized pointer casts, I felt it was necessary to document that the reinterpreting sized to sized casts produce identical values. I couldn't immediately find this documented.
This is because unsized to sized pointer casts also permits a reintepreting cast in the same sweep (such as *const [u8] as *const u32).
@RalfJung Can you review this?
I think this might be better structured in a different way... I'd make a single big section for raw-to-raw casts, which also handles once and for all the mut/const part:
#### Pointer-to-pointer cast
`*const T`/`*mut T` can be cast to `*const U`/`*mut U` under the following conditions:
- If both `T` and `U` are sized, [...]
- If both `T` and `U` are unsized, [...]
- If `T` is unsized and `U` is sized, [...]
Thanks for taking the time!
Note that if you want to change something, feel free to edit it directly (assuming that's enabled) if that is your preference. I only have an interest in the cast being documented - I don't mind how it's done or who does it.
For what it's worth, you have my +1.
This seems a bit stalled. Since I'm pretty much OK with this change, can we say that I wrote it and move forward? 😄
I think this would pretty much emulate the same scenario as if this was fully an external change proposed by me which was reviewed by Ralf. Or maybe @ehuss can give this a quick look over?
@udoprog please squash the PR into a single commit.
But yeah, for review would be good if @ehuss took a look. Maybe someone from @rust-lang/opsem can help as well.
Done