Hacker News new | ask | show | jobs
by tialaramex 55 days ago
> Can you roundtrip a pointer as `MaybeUninit<usize>`?

AIUI Strict Provenance rules imply that you can't expect any such tricks to work unless the target promised they would work.

You say "People rely on it" and I must ask: How many people and how sure are you that they actually can't live with Strict Provenance ?

1 comments

That's not true. Strict provenance says that you can not roundtrip a pointer via `usize` (with transmutes and not casts). You can via `MaybeUninit<usize>`. One of the fundamental properties of the language that is even specified explicitly (https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.h...) is that `MaybeUninit` preserves the exact Abstract Machine bytes, including provenance.
This manifestly can't work. Even if you can language lawyer your way to asserting that the words say this must work, it can't actually work in practice so the words are just wrong and I think other language lawyers will say that you must have understood the words wrong because "I'm correct, Up is actually Down" isn't helping anybody.