Skip to content

Commit d053175

Browse files
committed
fixup unsafe ops
Signed-off-by: tison <[email protected]>
1 parent 9cba3ed commit d053175

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

library/alloc/src/collections/vec_deque/extract_if.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,14 @@ where
114114
impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> {
115115
fn drop(&mut self) {
116116
if self.del > 0 {
117-
let idx = self.vec.to_physical_idx(self.idx);
117+
let src = self.vec.to_physical_idx(self.idx);
118+
let dst = self.vec.to_physical_idx(self.idx - self.del);
119+
let len = self.old_len - self.idx;
118120
// SAFETY: Trailing unchecked items must be valid since we never touch them.
119121
unsafe {
120-
ptr::copy(
121-
self.vec.ptr().add(idx),
122-
self.vec.ptr().add(idx - self.del),
123-
self.old_len - self.idx,
124-
);
122+
self.vec.wrap_copy(src, dst, len);
125123
}
126124
}
127-
// SAFETY: After filling holes, all items are in contiguous memory.
128125
self.vec.len = self.old_len - self.del;
129126
}
130127
}

0 commit comments

Comments
 (0)