Skip to content

Commit f99929f

Browse files
Remove some more consts
1 parent ab7b1cc commit f99929f

File tree

3 files changed

+50
-63
lines changed

3 files changed

+50
-63
lines changed

library/core/src/intrinsics.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1755,18 +1755,6 @@ pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
17551755
!ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
17561756
}
17571757

1758-
/// Checks whether the regions of memory starting at `src` and `dst` of size
1759-
/// `count * size_of::<T>()` do *not* overlap.
1760-
pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
1761-
let src_usize = src as usize;
1762-
let dst_usize = dst as usize;
1763-
let size = mem::size_of::<T>().checked_mul(count).unwrap();
1764-
let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
1765-
// If the absolute distance between the ptrs is at least as big as the size of the buffer,
1766-
// they do not overlap.
1767-
diff >= size
1768-
}
1769-
17701758
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
17711759
/// and destination must *not* overlap.
17721760
///

library/core/src/ptr/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,7 @@ const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
583583
/// ```
584584
#[inline]
585585
#[stable(feature = "rust1", since = "1.0.0")]
586-
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
587-
pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
586+
pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
588587
// SAFETY: the caller must guarantee that `dst` is valid to be
589588
// cast to a mutable reference (valid for writes, aligned, initialized),
590589
// and cannot overlap `src` since `dst` must point to a distinct

library/core/tests/const_ptr.rs

+49-49
Original file line numberDiff line numberDiff line change
@@ -50,52 +50,52 @@ fn mut_ptr_read() {
5050
assert_eq!(UNALIGNED, u16::from_ne_bytes([0x23, 0x45]));
5151
}
5252

53-
#[test]
54-
fn write() {
55-
use core::ptr;
56-
57-
const fn write_aligned() -> i32 {
58-
let mut res = 0;
59-
unsafe {
60-
ptr::write(&mut res as *mut _, 42);
61-
}
62-
res
63-
}
64-
const ALIGNED: i32 = write_aligned();
65-
assert_eq!(ALIGNED, 42);
66-
67-
const fn write_unaligned() -> [u16; 2] {
68-
let mut two_aligned = [0u16; 2];
69-
unsafe {
70-
let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16;
71-
ptr::write_unaligned(unaligned_ptr, u16::from_ne_bytes([0x23, 0x45]));
72-
}
73-
two_aligned
74-
}
75-
const UNALIGNED: [u16; 2] = write_unaligned();
76-
assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]);
77-
}
78-
79-
#[test]
80-
fn mut_ptr_write() {
81-
const fn aligned() -> i32 {
82-
let mut res = 0;
83-
unsafe {
84-
(&mut res as *mut i32).write(42);
85-
}
86-
res
87-
}
88-
const ALIGNED: i32 = aligned();
89-
assert_eq!(ALIGNED, 42);
90-
91-
const fn write_unaligned() -> [u16; 2] {
92-
let mut two_aligned = [0u16; 2];
93-
unsafe {
94-
let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16;
95-
unaligned_ptr.write_unaligned(u16::from_ne_bytes([0x23, 0x45]));
96-
}
97-
two_aligned
98-
}
99-
const UNALIGNED: [u16; 2] = write_unaligned();
100-
assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]);
101-
}
53+
//#[test]
54+
//fn write() {
55+
// use core::ptr;
56+
//
57+
// const fn write_aligned() -> i32 {
58+
// let mut res = 0;
59+
// unsafe {
60+
// ptr::write(&mut res as *mut _, 42);
61+
// }
62+
// res
63+
// }
64+
// const ALIGNED: i32 = write_aligned();
65+
// assert_eq!(ALIGNED, 42);
66+
//
67+
// const fn write_unaligned() -> [u16; 2] {
68+
// let mut two_aligned = [0u16; 2];
69+
// unsafe {
70+
// let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16;
71+
// ptr::write_unaligned(unaligned_ptr, u16::from_ne_bytes([0x23, 0x45]));
72+
// }
73+
// two_aligned
74+
// }
75+
// const UNALIGNED: [u16; 2] = write_unaligned();
76+
// assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]);
77+
//}
78+
79+
//#[test]
80+
//fn mut_ptr_write() {
81+
// const fn aligned() -> i32 {
82+
// let mut res = 0;
83+
// unsafe {
84+
// (&mut res as *mut i32).write(42);
85+
// }
86+
// res
87+
// }
88+
// const ALIGNED: i32 = aligned();
89+
// assert_eq!(ALIGNED, 42);
90+
//
91+
// const fn write_unaligned() -> [u16; 2] {
92+
// let mut two_aligned = [0u16; 2];
93+
// unsafe {
94+
// let unaligned_ptr = (two_aligned.as_mut_ptr() as *mut u8).add(1) as *mut u16;
95+
// unaligned_ptr.write_unaligned(u16::from_ne_bytes([0x23, 0x45]));
96+
// }
97+
// two_aligned
98+
// }
99+
// const UNALIGNED: [u16; 2] = write_unaligned();
100+
// assert_eq!(UNALIGNED, [u16::from_ne_bytes([0x00, 0x23]), u16::from_ne_bytes([0x45, 0x00])]);
101+
//}

0 commit comments

Comments
 (0)