mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2026-04-14 21:20:10 +00:00
Rollup merge of #152615 - RalfJung:null-not-valid-for-read-write, r=Mark-Simulacrum
refactor 'valid for read/write' definition: exclude null This is an attempt to resolve https://github.com/rust-lang/rust/issues/138351. The underlying problem is that when we decided to allow reads/writes/copies of size 0 even for null pointers, we documented that by changing the definition of "valid for read/write" in the standard library to say that null pointers are valid for 0-sized reads/writes. Unfortunately, that definition is also used in other places that assume that a valid-for-read/write pointer can be converted into a reference, and of course that's UB if the pointer is null, even if the pointee is a ZST. The proposal for fixing this is to make "valid for reads/writes" slightly [weaker](https://faultlore.com/blah/tower-of-weakenings/) than it has to be, and require the pointer to be non-null, and then to add exceptions to the most basic functions (read/write/copy) to explicitly allow arbitrary pointers when the size is 0. This isn't pretty but it's the best solution that has been suggested so far I think. Cc @rust-lang/opsem @rust-lang/libs-api
This commit is contained in: