Skip to content

Commit 0637cb7

Browse files
authored
Merge pull request #226 from clubby789/sb-fixes
Fix stacked borrows violations
2 parents a927f7c + c9ff579 commit 0637cb7

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/array_string.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,12 @@ impl<const CAP: usize> ArrayString<CAP>
371371

372372
let next = idx + ch.len_utf8();
373373
let len = self.len();
374+
let ptr = self.as_mut_ptr();
374375
unsafe {
375-
ptr::copy(self.as_ptr().add(next),
376-
self.as_mut_ptr().add(idx),
377-
len - next);
376+
ptr::copy(
377+
ptr.add(next),
378+
ptr.add(idx),
379+
len - next);
378380
self.set_len(len - (next - idx));
379381
}
380382
ch

src/arrayvec.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
507507
}
508508
if DELETED {
509509
unsafe {
510-
let hole_slot = g.v.as_mut_ptr().add(g.processed_len - g.deleted_cnt);
510+
let hole_slot = cur.sub(g.deleted_cnt);
511511
ptr::copy_nonoverlapping(cur, hole_slot, 1);
512512
}
513513
}
@@ -978,9 +978,8 @@ impl<'a, T: 'a, const CAP: usize> Drop for Drain<'a, T, CAP> {
978978
// memmove back untouched tail, update to new length
979979
let start = source_vec.len();
980980
let tail = self.tail_start;
981-
let src = source_vec.as_ptr().add(tail);
982-
let dst = source_vec.as_mut_ptr().add(start);
983-
ptr::copy(src, dst, self.tail_len);
981+
let ptr = source_vec.as_mut_ptr();
982+
ptr::copy(ptr.add(tail), ptr.add(start), self.tail_len);
984983
source_vec.set_len(start + self.tail_len);
985984
}
986985
}
@@ -1082,7 +1081,7 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
10821081
unsafe fn raw_ptr_add<T>(ptr: *mut T, offset: usize) -> *mut T {
10831082
if mem::size_of::<T>() == 0 {
10841083
// Special case for ZST
1085-
(ptr as usize).wrapping_add(offset) as _
1084+
ptr.cast::<u8>().wrapping_add(offset).cast()
10861085
} else {
10871086
ptr.add(offset)
10881087
}

0 commit comments

Comments
 (0)