Skip to content

Commit 18e2c0d

Browse files
RalfJunggitbot
authored and
gitbot
committed
rename typed_swap → typed_swap_nonoverlapping
1 parent 7cd8922 commit 18e2c0d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

core/src/intrinsics/mod.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -3940,6 +3940,21 @@ pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
39403940
false
39413941
}
39423942

3943+
#[rustc_nounwind]
3944+
#[inline]
3945+
#[rustc_intrinsic]
3946+
#[rustc_intrinsic_const_stable_indirect]
3947+
#[rustc_allow_const_fn_unstable(const_swap_nonoverlapping)] // this is anyway not called since CTFE implements the intrinsic
3948+
#[cfg(bootstrap)]
3949+
pub const unsafe fn typed_swap<T>(x: *mut T, y: *mut T) {
3950+
// SAFETY: The caller provided single non-overlapping items behind
3951+
// pointers, so swapping them with `count: 1` is fine.
3952+
unsafe { ptr::swap_nonoverlapping(x, y, 1) };
3953+
}
3954+
3955+
#[cfg(bootstrap)]
3956+
pub use typed_swap as typed_swap_nonoverlapping;
3957+
39433958
/// Non-overlapping *typed* swap of a single value.
39443959
///
39453960
/// The codegen backends will replace this with a better implementation when
@@ -3953,10 +3968,10 @@ pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
39533968
#[rustc_nounwind]
39543969
#[inline]
39553970
#[rustc_intrinsic]
3956-
// Const-unstable because `swap_nonoverlapping` is const-unstable.
39573971
#[rustc_intrinsic_const_stable_indirect]
39583972
#[rustc_allow_const_fn_unstable(const_swap_nonoverlapping)] // this is anyway not called since CTFE implements the intrinsic
3959-
pub const unsafe fn typed_swap<T>(x: *mut T, y: *mut T) {
3973+
#[cfg(not(bootstrap))]
3974+
pub const unsafe fn typed_swap_nonoverlapping<T>(x: *mut T, y: *mut T) {
39603975
// SAFETY: The caller provided single non-overlapping items behind
39613976
// pointers, so swapping them with `count: 1` is fine.
39623977
unsafe { ptr::swap_nonoverlapping(x, y, 1) };

core/src/mem/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ pub unsafe fn uninitialized<T>() -> T {
730730
pub const fn swap<T>(x: &mut T, y: &mut T) {
731731
// SAFETY: `&mut` guarantees these are typed readable and writable
732732
// as well as non-overlapping.
733-
unsafe { intrinsics::typed_swap(x, y) }
733+
unsafe { intrinsics::typed_swap_nonoverlapping(x, y) }
734734
}
735735

736736
/// Replaces `dest` with the default value of `T`, returning the previous `dest` value.

0 commit comments

Comments
 (0)