@@ -322,9 +322,8 @@ impl<'a> CoverageSpansGenerator<'a> {
322322 let prev = self . take_prev ( ) ;
323323 debug ! ( " AT END, adding last prev={prev:?}" ) ;
324324
325- // Take `pending_dups` so that we can drain it while calling self methods.
326- // It is never used as a field after this point.
327- for dup in std:: mem:: take ( & mut self . pending_dups ) {
325+ // Drain any remaining dups into the output.
326+ for dup in self . pending_dups . drain ( ..) {
328327 debug ! ( " ...adding at least one pending dup={:?}" , dup) ;
329328 self . refined_spans . push ( dup) ;
330329 }
@@ -453,19 +452,14 @@ impl<'a> CoverageSpansGenerator<'a> {
453452 previous iteration, or prev started a new disjoint span"
454453 ) ;
455454 if last_dup. span . hi ( ) <= self . curr ( ) . span . lo ( ) {
456- // Temporarily steal `pending_dups` into a local, so that we can
457- // drain it while calling other self methods.
458- let mut pending_dups = std:: mem:: take ( & mut self . pending_dups ) ;
459- for dup in pending_dups. drain ( ..) {
455+ for dup in self . pending_dups . drain ( ..) {
460456 debug ! ( " ...adding at least one pending={:?}" , dup) ;
461457 self . refined_spans . push ( dup) ;
462458 }
463- // The list of dups is now empty, but we can recycle its capacity.
464- assert ! ( pending_dups. is_empty( ) && self . pending_dups. is_empty( ) ) ;
465- self . pending_dups = pending_dups;
466459 } else {
467460 self . pending_dups . clear ( ) ;
468461 }
462+ assert ! ( self . pending_dups. is_empty( ) ) ;
469463 }
470464
471465 /// Advance `prev` to `curr` (if any), and `curr` to the next `CoverageSpan` in sorted order.
@@ -512,21 +506,17 @@ impl<'a> CoverageSpansGenerator<'a> {
512506 let has_pre_closure_span = prev. span . lo ( ) < right_cutoff;
513507 let has_post_closure_span = prev. span . hi ( ) > right_cutoff;
514508
515- // Temporarily steal `pending_dups` into a local, so that we can
516- // mutate and/or drain it while calling other self methods.
517- let mut pending_dups = std:: mem:: take ( & mut self . pending_dups ) ;
518-
519509 if has_pre_closure_span {
520510 let mut pre_closure = self . prev ( ) . clone ( ) ;
521511 pre_closure. span = pre_closure. span . with_hi ( left_cutoff) ;
522512 debug ! ( " prev overlaps a closure. Adding span for pre_closure={:?}" , pre_closure) ;
523- if !pending_dups. is_empty ( ) {
524- for mut dup in pending_dups. iter ( ) . cloned ( ) {
525- dup. span = dup. span . with_hi ( left_cutoff) ;
526- debug ! ( " ...and at least one pre_closure dup={:?}" , dup) ;
527- self . refined_spans . push ( dup) ;
528- }
513+
514+ for mut dup in self . pending_dups . iter ( ) . cloned ( ) {
515+ dup. span = dup. span . with_hi ( left_cutoff) ;
516+ debug ! ( " ...and at least one pre_closure dup={:?}" , dup) ;
517+ self . refined_spans . push ( dup) ;
529518 }
519+
530520 self . refined_spans . push ( pre_closure) ;
531521 }
532522
@@ -536,19 +526,17 @@ impl<'a> CoverageSpansGenerator<'a> {
536526 // about how the `CoverageSpan`s are ordered.)
537527 self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
538528 debug ! ( " Mutated prev.span to start after the closure. prev={:?}" , self . prev( ) ) ;
539- for dup in pending_dups. iter_mut ( ) {
529+
530+ for dup in & mut self . pending_dups {
540531 debug ! ( " ...and at least one overlapping dup={:?}" , dup) ;
541532 dup. span = dup. span . with_lo ( right_cutoff) ;
542533 }
534+
543535 let closure_covspan = self . take_curr ( ) ; // Prevent this curr from becoming prev.
544536 self . refined_spans . push ( closure_covspan) ; // since self.prev() was already updated
545537 } else {
546- pending_dups. clear ( ) ;
538+ self . pending_dups . clear ( ) ;
547539 }
548-
549- // Restore the modified post-closure spans, or the empty vector's capacity.
550- assert ! ( self . pending_dups. is_empty( ) ) ;
551- self . pending_dups = pending_dups;
552540 }
553541
554542 /// Called if `curr.span` equals `prev_original_span` (and potentially equal to all
0 commit comments