Skip to content

Commit 6f38bda

Browse files
committed
fixup compile
Signed-off-by: tison <[email protected]>
1 parent dbf8a13 commit 6f38bda

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ pub struct ExtractIf<
4040
}
4141

4242
impl<'a, T, F, A: Allocator> ExtractIf<'a, T, F, A> {
43-
pub(super) fn new<R: RangeBounds<usize>>(vec: &'a mut Vec<T, A>, pred: F, range: R) -> Self {
43+
pub(super) fn new<R: RangeBounds<usize>>(
44+
vec: &'a mut VecDeque<T, A>,
45+
pred: F,
46+
range: R,
47+
) -> Self {
4448
let old_len = vec.len();
4549
let Range { start, end } = slice::range(range, ..old_len);
4650

4751
// Guard against the deque getting leaked (leak amplification)
48-
unsafe {
49-
vec.len = len;
50-
}
52+
vec.len = len;
5153
ExtractIf { vec, idx: start, del: 0, end, old_len, pred }
5254
}
5355

@@ -78,8 +80,8 @@ where
7880
//
7981
// Note: we can't use `vec.get_mut(i).unwrap()` here since the precondition for that
8082
// function is that i < vec.len, but we've set vec's length to zero.
81-
let idx = self.to_physical_idx(index);
82-
let cur = unsafe { &mut *self.ptr().add(idx) };
83+
let idx = self.vec.to_physical_idx(i);
84+
let cur = unsafe { &mut *self.vec.ptr().add(idx) };
8385
let drained = (self.pred)(cur);
8486
// Update the index *after* the predicate is called. If the index
8587
// is updated prior and the predicate panics, the element at this
@@ -110,7 +112,7 @@ where
110112
impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> {
111113
fn drop(&mut self) {
112114
if self.del > 0 {
113-
let idx = self.to_physical_idx(self.idx);
115+
let idx = self.vec.to_physical_idx(self.idx);
114116
// SAFETY: Trailing unchecked items must be valid since we never touch them.
115117
unsafe {
116118
ptr::copy(
@@ -121,9 +123,7 @@ impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> {
121123
}
122124
}
123125
// SAFETY: After filling holes, all items are in contiguous memory.
124-
unsafe {
125-
self.vec.set_len(self.old_len - self.del);
126-
}
126+
self.vec.len = self.old_len - self.del;
127127
}
128128
}
129129

0 commit comments

Comments
 (0)