Skip to content

Commit 8cf12c5

Browse files
authored
Merge pull request #888 from NobodyXu/fix/retain-mut
Fix MSRV: Remove use of `Vec::retain_mut`
2 parents 4f9866e + fd2330c commit 8cf12c5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/lib.rs

Lines changed: 19 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,21 @@ 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+
///
4133+
/// TODO: Remove this once the MSRV is bumped to v1.61
4134+
#[cfg(feature = "parallel")]
4135+
fn retain_unordered_mut<T, F>(vec: &mut Vec<T>, mut f: F)
4136+
where
4137+
F: FnMut(&mut T) -> bool,
4138+
{
4139+
let mut i = 0;
4140+
while i < vec.len() {
4141+
if f(&mut vec[i]) {
4142+
i += 1;
4143+
} else {
4144+
vec.swap_remove(i);
4145+
}
4146+
}
4147+
}

0 commit comments

Comments
 (0)