@@ -143,7 +143,9 @@ impl PrevCovspan {
143
143
}
144
144
145
145
fn into_dup ( self ) -> DuplicateCovspan {
146
- let Self { original_span : _, span, bcb, merged_spans : _, is_closure } = self ;
146
+ let Self { original_span, span, bcb, merged_spans : _, is_closure } = self ;
147
+ // Only unmodified spans end up in `pending_dups`.
148
+ debug_assert_eq ! ( original_span, span) ;
147
149
DuplicateCovspan { span, bcb, is_closure }
148
150
}
149
151
@@ -287,9 +289,9 @@ impl<'a> SpansRefiner<'a> {
287
289
self . take_curr ( ) ; // Discards curr.
288
290
} else if curr. is_closure {
289
291
self . carve_out_span_for_closure ( ) ;
290
- } else if prev. original_span == curr. span {
291
- // `prev` and ` curr` have the same span, or would have had the
292
- // same span before `prev` was modified by other spans.
292
+ } else if prev. original_span == prev . span && prev . span == curr. span {
293
+ // Prev and curr have the same span, and prev's span hasn't
294
+ // been modified by other spans.
293
295
self . update_pending_dups ( ) ;
294
296
} else {
295
297
self . cutoff_prev_at_overlapping_curr ( ) ;
@@ -478,6 +480,12 @@ impl<'a> SpansRefiner<'a> {
478
480
// impossible for `curr` to dominate any previous coverage span.
479
481
debug_assert ! ( !self . basic_coverage_blocks. dominates( curr_bcb, prev_bcb) ) ;
480
482
483
+ // `prev` is a duplicate of `curr`, so add it to the list of pending dups.
484
+ // If it dominates `curr`, it will be removed by the subsequent discard step.
485
+ let prev = self . take_prev ( ) . into_dup ( ) ;
486
+ debug ! ( ?prev, "adding prev to pending dups" ) ;
487
+ self . pending_dups . push ( prev) ;
488
+
481
489
let initial_pending_count = self . pending_dups . len ( ) ;
482
490
if initial_pending_count > 0 {
483
491
self . pending_dups
@@ -490,42 +498,6 @@ impl<'a> SpansRefiner<'a> {
490
498
) ;
491
499
}
492
500
}
493
-
494
- if self . basic_coverage_blocks . dominates ( prev_bcb, curr_bcb) {
495
- debug ! (
496
- " different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}" ,
497
- self . prev( )
498
- ) ;
499
- self . cutoff_prev_at_overlapping_curr ( ) ;
500
- // If one span dominates the other, associate the span with the code from the dominated
501
- // block only (`curr`), and discard the overlapping portion of the `prev` span. (Note
502
- // that if `prev.span` is wider than `prev.original_span`, a coverage span will still
503
- // be created for `prev`s block, for the non-overlapping portion, left of `curr.span`.)
504
- //
505
- // For example:
506
- // match somenum {
507
- // x if x < 1 => { ... }
508
- // }...
509
- //
510
- // The span for the first `x` is referenced by both the pattern block (every time it is
511
- // evaluated) and the arm code (only when matched). The counter will be applied only to
512
- // the dominated block. This allows coverage to track and highlight things like the
513
- // assignment of `x` above, if the branch is matched, making `x` available to the arm
514
- // code; and to track and highlight the question mark `?` "try" operator at the end of
515
- // a function call returning a `Result`, so the `?` is covered when the function returns
516
- // an `Err`, and not counted as covered if the function always returns `Ok`.
517
- } else {
518
- // Save `prev` in `pending_dups`. (`curr` will become `prev` in the next iteration.)
519
- // If the `curr` span is later discarded, `pending_dups` can be discarded as
520
- // well; but if `curr` is added to refined_spans, the `pending_dups` will also be added.
521
- debug ! (
522
- " different bcbs but SAME spans, and neither dominates, so keep curr for \
523
- next iter, and, pending upcoming spans (unless overlapping) add prev={:?}",
524
- self . prev( )
525
- ) ;
526
- let prev = self . take_prev ( ) . into_dup ( ) ;
527
- self . pending_dups . push ( prev) ;
528
- }
529
501
}
530
502
531
503
/// `curr` overlaps `prev`. If `prev`s span extends left of `curr`s span, keep _only_
0 commit comments