Skip to content

Commit d10ff63

Browse files
committed
Auto merge of #27358 - bluss:split-at-mut, r=aturon
Use raw pointers to avoid aliasing violation in split_at_mut Fixes #27357
2 parents 6fcf628 + 73d4330 commit d10ff63

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/libcore/slice.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,12 @@ impl<T> SliceExt for [T] {
300300

301301
#[inline]
302302
fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
303+
let len = self.len();
304+
let ptr = self.as_mut_ptr();
305+
assert!(mid <= len);
303306
unsafe {
304-
let self2: &mut [T] = mem::transmute_copy(&self);
305-
306-
(ops::IndexMut::index_mut(self, ops::RangeTo { end: mid } ),
307-
ops::IndexMut::index_mut(self2, ops::RangeFrom { start: mid } ))
307+
(from_raw_parts_mut(ptr, mid),
308+
from_raw_parts_mut(ptr.offset(mid as isize), len - mid))
308309
}
309310
}
310311

0 commit comments

Comments
 (0)