rust-lang/unsafe-code-guidelines

Do the current nightly `std::ptr` docs violate provenance monotonicity?

joshlf opened this issue · 2 comments

joshlf commented

Per the nightly std::ptr docs:

[Under strict provenance, it is sound to] forge an allocation of size zero at any sufficiently aligned non-null address. i.e. the usual “ZSTs are fake, do what you want” rules apply but this only applies for actual forgery (integers cast to pointers). If you borrow some struct’s field that happens to be zero-sized, the resulting pointer will have provenance tied to that allocation, and it will still get invalidated if the allocation gets deallocated. In the future we may introduce an API to make such a forged allocation explicit.

Along the same lines as #529, IIUC this violates provenance monotonicity.

Yeah, this is indeed outdated. Will be fixed together with the big strict provenance docs update.