Skip to content

Commit 81fabcb

Browse files
japaricRalfJung
authored andcommitted
address Mark-Simulacrum comments
1 parent 318cfd5 commit 81fabcb

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/libcore/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
299299
let mut tmp = MaybeUninit::<T>::uninitialized();
300300

301301
// Perform the swap
302-
copy_nonoverlapping(x, tmp.get_mut(), 1);
302+
copy_nonoverlapping(x, tmp.as_mut_ptr(), 1);
303303
copy(y, x, 1); // `x` and `y` may overlap
304304
copy_nonoverlapping(tmp.get_ref(), y, 1);
305305
}
@@ -572,7 +572,7 @@ pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
572572
#[stable(feature = "rust1", since = "1.0.0")]
573573
pub unsafe fn read<T>(src: *const T) -> T {
574574
let mut tmp = MaybeUninit::<T>::uninitialized();
575-
copy_nonoverlapping(src, tmp.get_mut(), 1);
575+
copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
576576
tmp.into_inner()
577577
}
578578

src/libcore/slice/rotate.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ union RawArray<T> {
2626
}
2727

2828
impl<T> RawArray<T> {
29-
fn ptr(&self) -> *mut T {
30-
unsafe { &self.typed as *const T as *mut T }
31-
}
3229
fn cap() -> usize {
3330
if mem::size_of::<T>() == 0 {
3431
usize::max_value()
@@ -85,8 +82,8 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mid: *mut T, mut right: usize) {
8582
}
8683
}
8784

88-
let rawarray = MaybeUninit::<RawArray<T>>::uninitialized();
89-
let buf = rawarray.get_ref().ptr();
85+
let mut rawarray = MaybeUninit::<RawArray<T>>::uninitialized();
86+
let buf = &mut (*rawarray.as_mut_ptr()).typed as *mut [T; 2] as *mut T;
9087

9188
let dim = mid.sub(left).add(right);
9289
if left <= right {

src/libcore/slice/sort.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
272272

273273
if start_l == end_l {
274274
// Trace `block_l` elements from the left side.
275-
start_l = unsafe { offsets_l.get_mut().as_mut_ptr() };
276-
end_l = unsafe { offsets_l.get_mut().as_mut_ptr() };
275+
start_l = offsets_l.as_mut_ptr() as *mut u8;
276+
end_l = offsets_l.as_mut_ptr() as *mut u8;
277277
let mut elem = l;
278278

279279
for i in 0..block_l {
@@ -288,8 +288,8 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
288288

289289
if start_r == end_r {
290290
// Trace `block_r` elements from the right side.
291-
start_r = unsafe { offsets_r.get_mut().as_mut_ptr() };
292-
end_r = unsafe { offsets_r.get_mut().as_mut_ptr() };
291+
start_r = offsets_r.as_mut_ptr() as *mut u8;
292+
end_r = offsets_r.as_mut_ptr() as *mut u8;
293293
let mut elem = r;
294294

295295
for i in 0..block_r {

0 commit comments

Comments
 (0)