Closed
Description
The IsZero
trait is used to specialize vec![val; n]
to use allocate_zeroed
when the val
being duplicated is zero. But in the case of raw pointers, this is not correct as the bytes returned by allocate_zeroed
do not have the same provenance as val
. Thus, the following code triggers undefined behaviour (playground) when it shouldn't
let ptr = std::ptr::from_ref(&42);
let zero = ptr.with_addr(0);
let roundtripped = vec![zero; 1].pop().unwrap();
let new = roundtripped.with_addr(ptr.addr());
unsafe { new.read() };