ptr::replace: make calls on ZST null ptr not UB
See https://github.com/rust-lang/rust/issues/138351 for context.
We made ptr::read and ptr::write not UB on ZST null pointers. This does the same with ptr::replace. Since we're just adding a branch on a constant, this should come at no runtime cost.
r? @ibraheemdev
rustbot has assigned @ibraheemdev. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r? to explicitly pick a reviewer
@rust-lang/libs any thoughts on this?
Independent of what exactly we decide in https://github.com/rust-lang/rust/issues/138351, this seems like a basically free way to make replace have less UB and be more consistent with read and write.