@@ -243,14 +243,18 @@ pub struct CoverageSpans<'a, 'tcx> {
243
243
/// iteration.
244
244
some_curr : Option < CoverageSpan > ,
245
245
246
- /// The original `span` for `curr`, in case the `curr` span is modified.
246
+ /// The original `span` for `curr`, in case `curr.span()` is modified. The `curr_original_span`
247
+ /// **must not be mutated** (except when advancing to the next `curr`), even if `curr.span()`
248
+ /// is mutated.
247
249
curr_original_span : Span ,
248
250
249
251
/// The CoverageSpan from a prior iteration; typically assigned from that iteration's `curr`.
250
252
/// If that `curr` was discarded, `prev` retains its value from the previous iteration.
251
253
some_prev : Option < CoverageSpan > ,
252
254
253
- /// Assigned from `curr_original_span` from the previous iteration.
255
+ /// Assigned from `curr_original_span` from the previous iteration. The `prev_original_span`
256
+ /// **must not be mutated** (except when advancing to the next `prev`), even if `prev.span()`
257
+ /// is mutated.
254
258
prev_original_span : Span ,
255
259
256
260
/// A copy of the expn_span from the prior iteration.
@@ -400,8 +404,12 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
400
404
} else if self . curr ( ) . is_closure {
401
405
self . carve_out_span_for_closure ( ) ;
402
406
} else if self . prev_original_span == self . curr ( ) . span {
403
- // Note that this compares the new span to `prev_original_span`, which may not
404
- // be the full `prev.span` (if merged during the previous iteration).
407
+ // Note that this compares the new (`curr`) span to `prev_original_span`.
408
+ // In this branch, the actual span byte range of `prev_original_span` is not
409
+ // important. What is important is knowing whether the new `curr` span was
410
+ // **originally** the same as the original span of `prev()`. The original spans
411
+ // reflect their original sort order, and for equal spans, conveys a partial
412
+ // ordering based on CFG dominator priority.
405
413
if self . prev ( ) . is_macro_expansion ( ) && self . curr ( ) . is_macro_expansion ( ) {
406
414
// Macros that expand to include branching (such as
407
415
// `assert_eq!()`, `assert_ne!()`, `info!()`, `debug!()`, or
@@ -663,10 +671,13 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
663
671
self . push_refined_span ( pre_closure) ;
664
672
}
665
673
if has_post_closure_span {
666
- // Update prev.span to start after the closure (and discard curr)
674
+ // Mutate `prev.span()` to start after the closure (and discard curr).
675
+ // (**NEVER** update `prev_original_span` because it affects the assumptions
676
+ // about how the `CoverageSpan`s are ordered.)
667
677
self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
668
- self . prev_original_span = self . prev ( ) . span ;
678
+ debug ! ( " Mutated prev.span to start after the closure. prev={:?}" , self . prev( ) ) ;
669
679
for dup in pending_dups. iter_mut ( ) {
680
+ debug ! ( " ...and at least one overlapping dup={:?}" , dup) ;
670
681
dup. span = dup. span . with_lo ( right_cutoff) ;
671
682
}
672
683
self . pending_dups . append ( & mut pending_dups) ;
@@ -678,8 +689,14 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
678
689
}
679
690
680
691
/// Called if `curr.span` equals `prev_original_span` (and potentially equal to all
681
- /// `pending_dups` spans, if any); but keep in mind, `prev.span` may start at a `Span.lo()` that
682
- /// is less than (further left of) `prev_original_span.lo()`.
692
+ /// `pending_dups` spans, if any). Keep in mind, `prev.span()` may have been changed.
693
+ /// If prev.span() was merged into other spans (with matching BCB, for instance),
694
+ /// `prev.span.hi()` will be greater than (further right of) `prev_original_span.hi()`.
695
+ /// If prev.span() was split off to the right of a closure, prev.span().lo() will be
696
+ /// greater than prev_original_span.lo(). The actual span of `prev_original_span` is
697
+ /// not as important as knowing that `prev()` **used to have the same span** as `curr(),
698
+ /// which means their sort order is still meaningful for determinating the dominator
699
+ /// relationship.
683
700
///
684
701
/// When two `CoverageSpan`s have the same `Span`, dominated spans can be discarded; but if
685
702
/// neither `CoverageSpan` dominates the other, both (or possibly more than two) are held,
0 commit comments