Skip to content

Commit 5fbb135

Browse files
committed
Revert "Revert effects of PRs 81167 and 83091."
This reverts commit 9d96b0e.
1 parent 543ab99 commit 5fbb135

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

library/core/src/mem/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ pub unsafe fn uninitialized<T>() -> T {
682682
/// ```
683683
#[inline]
684684
#[stable(feature = "rust1", since = "1.0.0")]
685-
pub fn swap<T>(x: &mut T, y: &mut T) {
685+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
686+
pub const fn swap<T>(x: &mut T, y: &mut T) {
686687
// SAFETY: the raw pointers have been created from safe mutable references satisfying all the
687688
// constraints on `ptr::swap_nonoverlapping_one`
688689
unsafe {
@@ -812,7 +813,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
812813
#[inline]
813814
#[stable(feature = "rust1", since = "1.0.0")]
814815
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
815-
pub fn replace<T>(dest: &mut T, src: T) -> T {
816+
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
817+
pub const fn replace<T>(dest: &mut T, src: T) -> T {
816818
// SAFETY: We read from `dest` but directly write `src` into it afterwards,
817819
// such that the old value is not duplicated. Nothing is dropped and
818820
// nothing here can panic.

library/core/src/ptr/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
430430
}
431431

432432
#[inline]
433-
pub(crate) unsafe fn swap_nonoverlapping_one<T>(x: *mut T, y: *mut T) {
433+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
434+
pub(crate) const unsafe fn swap_nonoverlapping_one<T>(x: *mut T, y: *mut T) {
434435
// NOTE(eddyb) SPIR-V's Logical addressing model doesn't allow for arbitrary
435436
// reinterpretation of values as (chunkable) byte arrays, and the loop in the
436437
// block optimization in `swap_nonoverlapping_bytes` is hard to rewrite back
@@ -563,7 +564,8 @@ const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
563564
/// ```
564565
#[inline]
565566
#[stable(feature = "rust1", since = "1.0.0")]
566-
pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
567+
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
568+
pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
567569
// SAFETY: the caller must guarantee that `dst` is valid to be
568570
// cast to a mutable reference (valid for writes, aligned, initialized),
569571
// and cannot overlap `src` since `dst` must point to a distinct
@@ -869,10 +871,12 @@ pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
869871
/// ```
870872
#[inline]
871873
#[stable(feature = "rust1", since = "1.0.0")]
872-
pub unsafe fn write<T>(dst: *mut T, src: T) {
874+
#[rustc_const_unstable(feature = "const_ptr_write", issue = "none")]
875+
pub const unsafe fn write<T>(dst: *mut T, src: T) {
873876
// We are calling the intrinsics directly to avoid function calls in the generated code
874877
// as `intrinsics::copy_nonoverlapping` is a wrapper function.
875878
extern "rust-intrinsic" {
879+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "none")]
876880
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
877881
}
878882

library/core/src/ptr/mut_ptr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,9 @@ impl<T: ?Sized> *mut T {
10021002
///
10031003
/// [`ptr::write`]: crate::ptr::write()
10041004
#[stable(feature = "pointer_methods", since = "1.26.0")]
1005+
#[rustc_const_unstable(feature = "const_ptr_write", issue = "none")]
10051006
#[inline(always)]
1006-
pub unsafe fn write(self, val: T)
1007+
pub const unsafe fn write(self, val: T)
10071008
where
10081009
T: Sized,
10091010
{

0 commit comments

Comments
 (0)