Skip to content

Commit cfa8466

Browse files
authored
Rollup merge of rust-lang#114794 - RalfJung:swap-safety, r=m-ou-se
clarify safety documentation of ptr::swap and ptr::copy Closes rust-lang#81005
2 parents f222a2d + 4684ffa commit cfa8466

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: library/core/src/intrinsics.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2707,9 +2707,13 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
27072707
///
27082708
/// Behavior is undefined if any of the following conditions are violated:
27092709
///
2710-
/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2710+
/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes, and must remain valid even
2711+
/// when `dst` is written for `count * size_of::<T>()` bytes. (This means if the memory ranges
2712+
/// overlap, the two pointers must not be subject to aliasing restrictions relative to each
2713+
/// other.)
27112714
///
2712-
/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2715+
/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes, and must remain valid even
2716+
/// when `src` is read for `count * size_of::<T>()` bytes.
27132717
///
27142718
/// * Both `src` and `dst` must be properly aligned.
27152719
///

Diff for: library/core/src/ptr/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,9 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
795795
///
796796
/// Behavior is undefined if any of the following conditions are violated:
797797
///
798-
/// * Both `x` and `y` must be [valid] for both reads and writes.
798+
/// * Both `x` and `y` must be [valid] for both reads and writes. They must remain valid even when the
799+
/// other pointer is written. (This means if the memory ranges overlap, the two pointers must not
800+
/// be subject to aliasing restrictions relative to each other.)
799801
///
800802
/// * Both `x` and `y` must be properly aligned.
801803
///

0 commit comments

Comments
 (0)