Skip to content

Commit 34abe4e

Browse files
committed
use ExtractIf
1 parent e629869 commit 34abe4e

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

clippy_lints/src/unnested_or_patterns.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_ast::mut_visit::*;
1010
use rustc_ast::{self as ast, DUMMY_NODE_ID, Mutability, Pat, PatKind};
1111
use rustc_ast_pretty::pprust;
1212
use rustc_data_structures::thin_vec::{ThinVec, thin_vec};
13+
use rustc_data_structures::thinvec::ExtractIf;
1314
use rustc_errors::Applicability;
1415
use rustc_lint::{EarlyContext, EarlyLintPass};
1516
use rustc_session::impl_lint_pass;
@@ -415,26 +416,14 @@ fn drain_matching(
415416
let mut tail_or = ThinVec::new();
416417
let mut idx = 0;
417418

418-
// If `ThinVec` had the `drain_filter` method, this loop could be rewritten
419-
// like so:
420-
//
421-
// for pat in alternatives.drain_filter(|p| {
422-
// // Check if we should extract, but only if `idx >= start`.
423-
// idx += 1;
424-
// idx > start && predicate(&p.kind)
425-
// }) {
426-
// tail_or.push(extract(pat.into_inner().kind));
427-
// }
428-
let mut i = 0;
429-
while i < alternatives.len() {
430-
idx += 1;
419+
// FIXME: once `thin-vec` releases a new version, change this to `alternatives.extract_if()`
420+
// See https://github.com/mozilla/thin-vec/issues/77
421+
for pat in ExtractIf::new(alternatives, |p| {
431422
// Check if we should extract, but only if `idx >= start`.
432-
if idx > start && predicate(&alternatives[i].kind) {
433-
let pat = alternatives.remove(i);
434-
tail_or.push(extract(pat.kind));
435-
} else {
436-
i += 1;
437-
}
423+
idx += 1;
424+
idx > start && predicate(&p.kind)
425+
}) {
426+
tail_or.push(extract(pat.kind));
438427
}
439428

440429
tail_or

0 commit comments

Comments
 (0)