We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e22dab3 commit bb81fb2Copy full SHA for bb81fb2
library/core/src/ptr/mod.rs
@@ -1552,6 +1552,13 @@ pub const unsafe fn replace<T>(dst: *mut T, src: T) -> T {
1552
is_zst: bool = T::IS_ZST,
1553
) => ub_checks::maybe_is_aligned_and_not_null(addr, align, is_zst)
1554
);
1555
+ if T::IS_ZST {
1556
+ // `dst` may be valid for read and writes while also being null, in which case we cannot
1557
+ // call `mem::replace`. However, we also don't have to actually do anything since there
1558
+ // isn't actually any data to be copied anyway. All values of type `T` are
1559
+ // bit-identical, so we can just return `src`` here.
1560
+ return src;
1561
+ }
1562
mem::replace(&mut *dst, src)
1563
}
1564
0 commit comments