about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2021-05-03 14:41:52 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2021-05-03 14:52:12 -0400
commitf99929f24aa5cb3962dfa8c45afe76a262376238 (patch)
treea1050845879fb5e6242eb7a5908d6cf5b699d639
parentab7b1cca2dbd73a8c253c896055a04a06f1aaf17 (diff)
downloadrust-f99929f24aa5cb3962dfa8c45afe76a262376238.tar.gz
rust-f99929f24aa5cb3962dfa8c45afe76a262376238.zip
Remove some more consts
-rw-r--r--library/core/src/intrinsics.rs12
-rw-r--r--library/core/src/ptr/mod.rs3
-rw-r--r--library/core/tests/const_ptr.rs98
3 files changed, 50 insertions, 63 deletions
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs
index 84fd3124107..073210c5b68 100644
--- a/library/core/src/intrinsics.rs
+++ b/library/core/src/intrinsics.rs
@@ -1755,18 +1755,6 @@ pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
     !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
 }
 
-/// Checks whether the regions of memory starting at `src` and `dst` of size
-/// `count * size_of::<T>()` do *not* overlap.
-pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
-    let src_usize = src as usize;
-    let dst_usize = dst as usize;
-    let size = mem::size_of::<T>().checked_mul(count).unwrap();
-    let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
-    // If the absolute distance between the ptrs is at least as big as the size of the buffer,
-    // they do not overlap.
-    diff >= size
-}
-
 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
 /// and destination must *not* overlap.
 ///
diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs
index 67185217d5e..fd24469bd3c 100644
--- a/library/core/src/ptr/mod.rs
+++ b/library/core/src/ptr/mod.rs
@@ -583,8 +583,7 @@ const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
 /// ```
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
-pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
+pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
     // SAFETY: the caller must guarantee that `dst` is valid to be
     // cast to a mutable reference (valid for writes, aligned, initialized),
     // and cannot overlap `src` since `dst` must point to a distinct
diff --git a/library/core/tests/const_ptr.rs b/library/core/tests/const_ptr.rs
index 152fed803ec..4158a4dece7 100644
--- a/library/core/tests/const_ptr.rs
+++ b/library/core/tests/const_ptr.rs
@@ -50,52 +50,52 @@ fn mut_ptr_read() {
     assert_eq!(UNALIGNED, u16::from_ne_bytes([0x23, 0x45]));
 }
 
-#[test]
-fn write() {
-    use core::ptr;
-
-    const fn write_aligned() -> i32 {
-        let mut res = 0;
-        unsafe {
-            ptr::write(&mut res as *mut _, 42);
-        }
-        res
-    }
-    const ALIGNED: i32 = write_aligned();
-    assert_eq!(ALIGNED, 42);
-
-    const fn write_unaligned() -> [u16; 2] {
-        let mut two_aligned = [0u16; 2];
-        unsafe {
-            let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16;
-            ptr::write_unaligned(unaligned_ptr, u16::from_ne_bytes([0x23, 0x45]));
-        }
-        two_aligned
-    }
-    const UNALIGNED: [u16; 2] = write_unaligned();
-    assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]);
-}
-
-#[test]
-fn mut_ptr_write() {
-    const fn aligned() -> i32 {
-        let mut res = 0;
-        unsafe {
-            (&mut res as *mut i32).write(42);
-        }
-        res
-    }
-    const ALIGNED: i32 = aligned();
-    assert_eq!(ALIGNED, 42);
-
-    const fn write_unaligned() -> [u16; 2] {
-        let mut two_aligned = [0u16; 2];
-        unsafe {
-            let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16;
-            unaligned_ptr.write_unaligned(u16::from_ne_bytes([0x23, 0x45]));
-        }
-        two_aligned
-    }
-    const UNALIGNED: [u16; 2] = write_unaligned();
-    assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]);
-}
+//#[test]
+//fn write() {
+//    use core::ptr;
+//
+//    const fn write_aligned() -> i32 {
+//        let mut res = 0;
+//        unsafe {
+//            ptr::write(&mut res as *mut _, 42);
+//        }
+//        res
+//    }
+//    const ALIGNED: i32 = write_aligned();
+//    assert_eq!(ALIGNED, 42);
+//
+//    const fn write_unaligned() -> [u16; 2] {
+//        let mut two_aligned = [0u16; 2];
+//        unsafe {
+//            let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16;
+//            ptr::write_unaligned(unaligned_ptr, u16::from_ne_bytes([0x23, 0x45]));
+//        }
+//        two_aligned
+//    }
+//    const UNALIGNED: [u16; 2] = write_unaligned();
+//    assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]);
+//}
+
+//#[test]
+//fn mut_ptr_write() {
+//    const fn aligned() -> i32 {
+//        let mut res = 0;
+//        unsafe {
+//            (&mut res as *mut i32).write(42);
+//        }
+//        res
+//    }
+//    const ALIGNED: i32 = aligned();
+//    assert_eq!(ALIGNED, 42);
+//
+//    const fn write_unaligned() -> [u16; 2] {
+//        let mut two_aligned = [0u16; 2];
+//        unsafe {
+//            let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16;
+//            unaligned_ptr.write_unaligned(u16::from_ne_bytes([0x23, 0x45]));
+//        }
+//        two_aligned
+//    }
+//    const UNALIGNED: [u16; 2] = write_unaligned();
+//    assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]);
+//}