Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b5230c0

Browse files
authoredMar 16, 2025
Unrolled build for rust-lang#138309
Rollup merge of rust-lang#138309 - DiuDiu777:intrinsic-doc-fix, r=thomcc Add missing doc for intrinsic (Fix PR135334) The previous [PR135334](rust-lang#135334) mentioned that some of the intrinsic APIs were missing safety descriptions. Among intrinsic APIs that miss safety specifications, most are related to numerical operations. They might need to be discussed and then seen how to organize. Apart from them, only a few intrinsics lack safety. So this PR deals with the APIs with non-numerical operations in priority.
2 parents 9f274ba + 2f824ea commit b5230c0

File tree

1 file changed

+24
-7
lines changed
  • library/core/src/intrinsics

1 file changed

+24
-7
lines changed
 

‎library/core/src/intrinsics/mod.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -1774,10 +1774,14 @@ pub fn ptr_mask<T>(ptr: *const T, mask: usize) -> *const T;
17741774
/// a size of `count` * `size_of::<T>()` and an alignment of
17751775
/// `min_align_of::<T>()`
17761776
///
1777-
/// The volatile parameter is set to `true`, so it will not be optimized out
1778-
/// unless size is equal to zero.
1779-
///
17801777
/// This intrinsic does not have a stable counterpart.
1778+
/// # Safety
1779+
///
1780+
/// The safety requirements are consistent with [`copy_nonoverlapping`]
1781+
/// while the read and write behaviors are volatile,
1782+
/// which means it will not be optimized out unless `_count` or `size_of::<T>()` is equal to zero.
1783+
///
1784+
/// [`copy_nonoverlapping`]: ptr::copy_nonoverlapping
17811785
#[rustc_intrinsic]
17821786
#[rustc_nounwind]
17831787
pub unsafe fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
@@ -1796,10 +1800,13 @@ pub unsafe fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
17961800
/// size of `count * size_of::<T>()` and an alignment of
17971801
/// `min_align_of::<T>()`.
17981802
///
1799-
/// The volatile parameter is set to `true`, so it will not be optimized out
1800-
/// unless size is equal to zero.
1801-
///
18021803
/// This intrinsic does not have a stable counterpart.
1804+
/// # Safety
1805+
///
1806+
/// The safety requirements are consistent with [`write_bytes`] while the write behavior is volatile,
1807+
/// which means it will not be optimized out unless `_count` or `size_of::<T>()` is equal to zero.
1808+
///
1809+
/// [`write_bytes`]: ptr::write_bytes
18031810
#[rustc_intrinsic]
18041811
#[rustc_nounwind]
18051812
pub unsafe fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
@@ -3341,8 +3348,18 @@ pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
33413348
/// The stabilized form of this intrinsic is [`crate::mem::swap`].
33423349
///
33433350
/// # Safety
3351+
/// Behavior is undefined if any of the following conditions are violated:
3352+
///
3353+
/// * Both `x` and `y` must be [valid] for both reads and writes.
33443354
///
3345-
/// `x` and `y` are readable and writable as `T`, and non-overlapping.
3355+
/// * Both `x` and `y` must be properly aligned.
3356+
///
3357+
/// * The region of memory beginning at `x` must *not* overlap with the region of memory
3358+
/// beginning at `y`.
3359+
///
3360+
/// * The memory pointed by `x` and `y` must both contain values of type `T`.
3361+
///
3362+
/// [valid]: crate::ptr#safety
33463363
#[rustc_nounwind]
33473364
#[inline]
33483365
#[rustc_intrinsic]

0 commit comments

Comments
 (0)
Failed to load comments.