Skip to content

Commit a7d0a43

Browse files
committed
address comment
Signed-off-by: tison <[email protected]>
1 parent 2915a63 commit a7d0a43

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,10 @@ where
9494
// SAFETY: We never touch this element again after returning it.
9595
return Some(unsafe { ptr::read(cur) });
9696
} else if self.del > 0 {
97+
let hole_slot = self.vec.to_physical_idx(i - self.del);
9798
// SAFETY: `self.del` > 0, so the hole slot must not overlap with current element.
9899
// We use copy for move, and never touch this element again.
99-
unsafe {
100-
let hole_slot = self.vec.ptr().add(idx - self.del);
101-
ptr::copy_nonoverlapping(cur, hole_slot, 1);
102-
}
100+
unsafe { self.vec.wrap_copy(idx, hole_slot, 1) };
103101
}
104102
}
105103
None
@@ -118,9 +116,7 @@ impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> {
118116
let dst = self.vec.to_physical_idx(self.idx - self.del);
119117
let len = self.old_len - self.idx;
120118
// SAFETY: Trailing unchecked items must be valid since we never touch them.
121-
unsafe {
122-
self.vec.wrap_copy(src, dst, len);
123-
}
119+
unsafe { self.vec.wrap_copy(src, dst, len) };
124120
}
125121
self.vec.len = self.old_len - self.del;
126122
}

0 commit comments

Comments
 (0)