reference icon indicating copy to clipboard operation
reference copied to clipboard

Clarify semantics of the various pointer to pointer casts

Open udoprog opened this issue 1 year ago • 4 comments

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).

udoprog avatar Jan 22 '24 05:01 udoprog

@RalfJung Can you review this?

ehuss avatar Jan 22 '24 13:01 ehuss

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, [...]

RalfJung avatar Jan 24 '24 16:01 RalfJung

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.

udoprog avatar Jan 24 '24 18:01 udoprog

For what it's worth, you have my +1.

udoprog avatar Jan 26 '24 17:01 udoprog

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 avatar Feb 20 '24 15:02 udoprog

@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.

RalfJung avatar Feb 21 '24 07:02 RalfJung

Done

udoprog avatar Feb 21 '24 20:02 udoprog