Skip to content

Commit 2adc336

Browse files
committed
Fix MSRV: Remove use of Vec::retain_mut
And replace that with our own implementation of `retain_unordered_mut` which is usable under any rust version after v1.0 Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
1 parent 4f9866e commit 2adc336

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ impl Build {
13721372
}
13731373

13741374
// Try waiting on them.
1375-
pendings.retain_mut(|(cmd, program, child, token)| {
1375+
retain_unordered_mut(&mut pendings, |(cmd, program, child, token)| {
13761376
match try_wait_on_child(cmd, program, &mut child.0, &mut stdout) {
13771377
Ok(Some(())) => {
13781378
// Task done, remove the entry
@@ -4127,3 +4127,19 @@ impl Drop for PrintThread {
41274127
self.handle.take().unwrap().join().unwrap();
41284128
}
41294129
}
4130+
4131+
/// Remove all element in `vec` which `f(element)` returns `false`.
4132+
#[cfg(feature = "parallel")]
4133+
fn retain_unordered_mut<T, F>(vec: &mut Vec<T>, mut f: F)
4134+
where
4135+
F: FnMut(&mut T) -> bool,
4136+
{
4137+
let mut i = 0;
4138+
while i < vec.len() {
4139+
if f(&mut vec[i]) {
4140+
i += 1;
4141+
} else {
4142+
vec.swap_remove(i);
4143+
}
4144+
}
4145+
}

0 commit comments

Comments
 (0)