@@ -322,9 +322,8 @@ impl<'a> CoverageSpansGenerator<'a> {
322
322
let prev = self . take_prev ( ) ;
323
323
debug ! ( " AT END, adding last prev={prev:?}" ) ;
324
324
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 ( ..) {
328
327
debug ! ( " ...adding at least one pending dup={:?}" , dup) ;
329
328
self . refined_spans . push ( dup) ;
330
329
}
@@ -453,19 +452,14 @@ impl<'a> CoverageSpansGenerator<'a> {
453
452
previous iteration, or prev started a new disjoint span"
454
453
) ;
455
454
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 ( ..) {
460
456
debug ! ( " ...adding at least one pending={:?}" , dup) ;
461
457
self . refined_spans . push ( dup) ;
462
458
}
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;
466
459
} else {
467
460
self . pending_dups . clear ( ) ;
468
461
}
462
+ assert ! ( self . pending_dups. is_empty( ) ) ;
469
463
}
470
464
471
465
/// Advance `prev` to `curr` (if any), and `curr` to the next `CoverageSpan` in sorted order.
@@ -512,21 +506,17 @@ impl<'a> CoverageSpansGenerator<'a> {
512
506
let has_pre_closure_span = prev. span . lo ( ) < right_cutoff;
513
507
let has_post_closure_span = prev. span . hi ( ) > right_cutoff;
514
508
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
-
519
509
if has_pre_closure_span {
520
510
let mut pre_closure = self . prev ( ) . clone ( ) ;
521
511
pre_closure. span = pre_closure. span . with_hi ( left_cutoff) ;
522
512
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) ;
529
518
}
519
+
530
520
self . refined_spans . push ( pre_closure) ;
531
521
}
532
522
@@ -536,19 +526,17 @@ impl<'a> CoverageSpansGenerator<'a> {
536
526
// about how the `CoverageSpan`s are ordered.)
537
527
self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
538
528
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 {
540
531
debug ! ( " ...and at least one overlapping dup={:?}" , dup) ;
541
532
dup. span = dup. span . with_lo ( right_cutoff) ;
542
533
}
534
+
543
535
let closure_covspan = self . take_curr ( ) ; // Prevent this curr from becoming prev.
544
536
self . refined_spans . push ( closure_covspan) ; // since self.prev() was already updated
545
537
} else {
546
- pending_dups. clear ( ) ;
538
+ self . pending_dups . clear ( ) ;
547
539
}
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;
552
540
}
553
541
554
542
/// Called if `curr.span` equals `prev_original_span` (and potentially equal to all
0 commit comments