@@ -10,6 +10,7 @@ use rustc_ast::mut_visit::*;
1010use rustc_ast:: { self as ast, DUMMY_NODE_ID , Mutability , Pat , PatKind } ;
1111use rustc_ast_pretty:: pprust;
1212use rustc_data_structures:: thin_vec:: { ThinVec , thin_vec} ;
13+ use rustc_data_structures:: thinvec:: ExtractIf ;
1314use rustc_errors:: Applicability ;
1415use rustc_lint:: { EarlyContext , EarlyLintPass } ;
1516use 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