From b9c15c5d3bfb503676fffccab69fe27c5b532283 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 14 Aug 2023 09:40:09 +0200 Subject: [PATCH] clarify safety documentation of ptr::swap and ptr::copy --- library/core/src/intrinsics.rs | 3 +++ library/core/src/ptr/mod.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 9ef2c7cde02e..84b9a3bba88e 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2709,6 +2709,9 @@ pub const unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: us /// /// * `dst` must be [valid] for writes of `count * size_of::()` bytes. /// +/// * `src` must remain valid for reads even after `dst` is written, and vice versa. +/// (In other words, there cannot be aliasing restrictions on the use of these pointers.) +/// /// * Both `src` and `dst` must be properly aligned. /// /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 5f094ac4e7e6..f8badc4130dc 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -797,6 +797,9 @@ pub const fn slice_from_raw_parts_mut(data: *mut T, len: usize) -> *mut [T] { /// /// * Both `x` and `y` must be [valid] for both reads and writes. /// +/// * `x` must remain valid for reads and writes even after `y` is read/written, and vice versa. +/// (In other words, there cannot be aliasing restrictions on the use of these pointers.) +/// /// * Both `x` and `y` must be properly aligned. /// /// Note that even if `T` has size `0`, the pointers must be non-null and properly aligned.