Skip to content

Commit b9c15c5

Browse files
committed
clarify safety documentation of ptr::swap and ptr::copy
1 parent 3071e0a commit b9c15c5

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

library/core/src/intrinsics.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,9 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
27092709
///
27102710
/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
27112711
///
2712+
/// * `src` must remain valid for reads even after `dst` is written, and vice versa.
2713+
/// (In other words, there cannot be aliasing restrictions on the use of these pointers.)
2714+
///
27122715
/// * Both `src` and `dst` must be properly aligned.
27132716
///
27142717
/// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of

library/core/src/ptr/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,9 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
797797
///
798798
/// * Both `x` and `y` must be [valid] for both reads and writes.
799799
///
800+
/// * `x` must remain valid for reads and writes even after `y` is read/written, and vice versa.
801+
/// (In other words, there cannot be aliasing restrictions on the use of these pointers.)
802+
///
800803
/// * Both `x` and `y` must be properly aligned.
801804
///
802805
/// Note that even if `T` has size `0`, the pointers must be non-null and properly aligned.

0 commit comments

Comments
 (0)