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