From 48a54d026d632ac88ce08dee1462c31ed1071ca5 Mon Sep 17 00:00:00 2001 From: LemonJ <1632798336@qq.com> Date: Mon, 10 Mar 2025 22:08:30 +0800 Subject: [PATCH 1/4] add missing doc for intrinsic --- library/core/src/intrinsics/mod.rs | 31 +++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 6af647b137dac..4fa6df9f5525a 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -1630,10 +1630,14 @@ pub fn ptr_mask(_ptr: *const T, _mask: usize) -> *const T; /// a size of `count` * `size_of::()` and an alignment of /// `min_align_of::()` /// -/// The volatile parameter is set to `true`, so it will not be optimized out -/// unless size is equal to zero. -/// /// This intrinsic does not have a stable counterpart. +/// # Safety +/// +/// The safety requirements are consistent with [`copy_nonoverlapping`] +/// while the read and write behaviors are volatile, +/// which means it will not be optimized out unless size is equal to zero. +/// +/// [`copy_nonoverlapping`]: ptr::copy_nonoverlapping #[rustc_intrinsic] #[rustc_nounwind] pub unsafe fn volatile_copy_nonoverlapping_memory(_dst: *mut T, _src: *const T, _count: usize); @@ -1652,10 +1656,13 @@ pub unsafe fn volatile_copy_memory(_dst: *mut T, _src: *const T, _count: usiz /// size of `count * size_of::()` and an alignment of /// `min_align_of::()`. /// -/// The volatile parameter is set to `true`, so it will not be optimized out -/// unless size is equal to zero. -/// /// This intrinsic does not have a stable counterpart. +/// # Safety +/// +/// The safety requirements are consistent with [`write_bytes`] while the write behavior is volatile, +/// which means it will not be optimized out unless size is equal to zero. +/// +/// [`write_bytes`]: ptr::write_bytes #[rustc_intrinsic] #[rustc_nounwind] pub unsafe fn volatile_set_memory(_dst: *mut T, _val: u8, _count: usize); @@ -3197,8 +3204,18 @@ pub const fn is_val_statically_known(_arg: T) -> bool { /// The stabilized form of this intrinsic is [`crate::mem::swap`]. /// /// # Safety +/// Behavior is undefined if any of the following conditions are violated: +/// +/// * Both `x` and `y` must be [valid] for both reads and writes. /// -/// `x` and `y` are readable and writable as `T`, and non-overlapping. +/// * Both `x` and `y` must be properly aligned. +/// +/// * The region of memory beginning at `x` must *not* overlap with the region of memory +/// beginning at `y`. +/// +/// * The memory pointed by `x` and `y` must contain correct value of type `T`. +/// +/// [valid]: crate::ptr#safety #[rustc_nounwind] #[inline] #[rustc_intrinsic] From d2ff65807c5babc8066e789b60092c45cfef32c0 Mon Sep 17 00:00:00 2001 From: ClearLove <98693523+DiuDiu777@users.noreply.github.com> Date: Thu, 13 Mar 2025 11:33:55 +0800 Subject: [PATCH 2/4] Update library/core/src/intrinsics/mod.rs Co-authored-by: Thom Chiovoloni --- library/core/src/intrinsics/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 4fa6df9f5525a..8055c7c0bc25f 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -3213,7 +3213,7 @@ pub const fn is_val_statically_known(_arg: T) -> bool { /// * The region of memory beginning at `x` must *not* overlap with the region of memory /// beginning at `y`. /// -/// * The memory pointed by `x` and `y` must contain correct value of type `T`. +/// * The memory pointed by `x` and `y` must both contain values of type `T`. /// /// [valid]: crate::ptr#safety #[rustc_nounwind] From 6a0199021548bc42a5aa1d41cd69499afaba448a Mon Sep 17 00:00:00 2001 From: ClearLove <98693523+DiuDiu777@users.noreply.github.com> Date: Thu, 13 Mar 2025 11:34:06 +0800 Subject: [PATCH 3/4] Update library/core/src/intrinsics/mod.rs Co-authored-by: Thom Chiovoloni --- library/core/src/intrinsics/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 8055c7c0bc25f..be2cfd3f3edb7 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -1660,7 +1660,7 @@ pub unsafe fn volatile_copy_memory(_dst: *mut T, _src: *const T, _count: usiz /// # Safety /// /// The safety requirements are consistent with [`write_bytes`] while the write behavior is volatile, -/// which means it will not be optimized out unless size is equal to zero. +/// which means it will not be optimized out unless `_count` or `size_of::()` is equal to zero. /// /// [`write_bytes`]: ptr::write_bytes #[rustc_intrinsic] From 2f824ea429cf09a9816baa3d4b55c551896838fe Mon Sep 17 00:00:00 2001 From: ClearLove <98693523+DiuDiu777@users.noreply.github.com> Date: Thu, 13 Mar 2025 11:34:18 +0800 Subject: [PATCH 4/4] Update library/core/src/intrinsics/mod.rs Co-authored-by: Thom Chiovoloni --- library/core/src/intrinsics/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index be2cfd3f3edb7..ce8c8c8946ef1 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -1635,7 +1635,7 @@ pub fn ptr_mask(_ptr: *const T, _mask: usize) -> *const T; /// /// The safety requirements are consistent with [`copy_nonoverlapping`] /// while the read and write behaviors are volatile, -/// which means it will not be optimized out unless size is equal to zero. +/// which means it will not be optimized out unless `_count` or `size_of::()` is equal to zero. /// /// [`copy_nonoverlapping`]: ptr::copy_nonoverlapping #[rustc_intrinsic]