11use rustc_data_structures:: graph:: WithNumNodes ;
22use rustc_index:: bit_set:: BitSet ;
33use rustc_middle:: mir;
4- use rustc_span:: { BytePos , Span , DUMMY_SP } ;
4+ use rustc_span:: { BytePos , Span } ;
55
66use crate :: coverage:: graph:: { BasicCoverageBlock , CoverageGraph , START_BCB } ;
77use crate :: coverage:: spans:: from_mir:: SpanFromMir ;
@@ -102,7 +102,7 @@ impl CurrCovspan {
102102
103103 fn into_prev ( self ) -> PrevCovspan {
104104 let Self { span, bcb, is_closure } = self ;
105- PrevCovspan { span, bcb, merged_spans : vec ! [ span] , is_closure }
105+ PrevCovspan { original_span : span , span, bcb, merged_spans : vec ! [ span] , is_closure }
106106 }
107107
108108 fn into_refined ( self ) -> RefinedCovspan {
@@ -115,6 +115,7 @@ impl CurrCovspan {
115115
116116#[ derive( Debug ) ]
117117struct PrevCovspan {
118+ original_span : Span ,
118119 span : Span ,
119120 bcb : BasicCoverageBlock ,
120121 /// List of all the original spans from MIR that have been merged into this
@@ -142,12 +143,12 @@ impl PrevCovspan {
142143 }
143144
144145 fn into_dup ( self ) -> DuplicateCovspan {
145- let Self { span, bcb, merged_spans : _, is_closure } = self ;
146+ let Self { original_span : _ , span, bcb, merged_spans : _, is_closure } = self ;
146147 DuplicateCovspan { span, bcb, is_closure }
147148 }
148149
149150 fn refined_copy ( & self ) -> RefinedCovspan {
150- let & Self { span, bcb, merged_spans : _, is_closure } = self ;
151+ let & Self { original_span : _ , span, bcb, merged_spans : _, is_closure } = self ;
151152 RefinedCovspan { span, bcb, is_closure }
152153 }
153154
@@ -220,11 +221,6 @@ struct SpansRefiner<'a> {
220221 /// If that `curr` was discarded, `prev` retains its value from the previous iteration.
221222 some_prev : Option < PrevCovspan > ,
222223
223- /// Assigned from `curr.span` from the previous iteration. The `prev_original_span`
224- /// **must not be mutated** (except when advancing to the next `prev`), even if `prev.span()`
225- /// is mutated.
226- prev_original_span : Span ,
227-
228224 /// One or more coverage spans with the same `Span` but different `BasicCoverageBlock`s, and
229225 /// no `BasicCoverageBlock` in this list dominates another `BasicCoverageBlock` in the list.
230226 /// If a new `curr` span also fits this criteria (compared to an existing list of
@@ -253,7 +249,6 @@ impl<'a> SpansRefiner<'a> {
253249 sorted_spans_iter : sorted_spans. into_iter ( ) ,
254250 some_curr : None ,
255251 some_prev : None ,
256- prev_original_span : DUMMY_SP ,
257252 pending_dups : Vec :: new ( ) ,
258253 refined_spans : Vec :: with_capacity ( basic_coverage_blocks. num_nodes ( ) * 2 ) ,
259254 } ;
@@ -295,7 +290,7 @@ impl<'a> SpansRefiner<'a> {
295290 self . take_curr ( ) ; // Discards curr.
296291 } else if curr. is_closure {
297292 self . carve_out_span_for_closure ( ) ;
298- } else if self . prev_original_span == curr. span {
293+ } else if prev . original_span == curr. span {
299294 // `prev` and `curr` have the same span, or would have had the
300295 // same span before `prev` was modified by other spans.
301296 self . update_pending_dups ( ) ;
@@ -395,7 +390,6 @@ impl<'a> SpansRefiner<'a> {
395390 /// Advance `prev` to `curr` (if any), and `curr` to the next coverage span in sorted order.
396391 fn next_coverage_span ( & mut self ) -> bool {
397392 if let Some ( curr) = self . some_curr . take ( ) {
398- self . prev_original_span = curr. span ;
399393 self . some_prev = Some ( curr. into_prev ( ) ) ;
400394 }
401395 while let Some ( curr) = self . sorted_spans_iter . next ( ) {
@@ -448,9 +442,7 @@ impl<'a> SpansRefiner<'a> {
448442 }
449443
450444 if has_post_closure_span {
451- // Mutate `prev.span()` to start after the closure (and discard curr).
452- // (**NEVER** update `prev_original_span` because it affects the assumptions
453- // about how the coverage spans are ordered.)
445+ // Mutate `prev.span` to start after the closure (and discard curr).
454446 self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
455447 debug ! ( " Mutated prev.span to start after the closure. prev={:?}" , self . prev( ) ) ;
456448
@@ -467,12 +459,12 @@ impl<'a> SpansRefiner<'a> {
467459 }
468460 }
469461
470- /// Called if `curr.span` equals `prev_original_span ` (and potentially equal to all
462+ /// Called if `curr.span` equals `prev.original_span ` (and potentially equal to all
471463 /// `pending_dups` spans, if any). Keep in mind, `prev.span()` may have been changed.
472464 /// If prev.span() was merged into other spans (with matching BCB, for instance),
473- /// `prev.span.hi()` will be greater than (further right of) `prev_original_span .hi()`.
465+ /// `prev.span.hi()` will be greater than (further right of) `prev.original_span .hi()`.
474466 /// If prev.span() was split off to the right of a closure, prev.span().lo() will be
475- /// greater than prev_original_span. lo(). The actual span of `prev_original_span ` is
467+ /// greater than prev.original_span. lo(). The actual span of `prev.original_span ` is
476468 /// not as important as knowing that `prev()` **used to have the same span** as `curr()`,
477469 /// which means their sort order is still meaningful for determining the dominator
478470 /// relationship.
@@ -510,7 +502,7 @@ impl<'a> SpansRefiner<'a> {
510502 self . cutoff_prev_at_overlapping_curr ( ) ;
511503 // If one span dominates the other, associate the span with the code from the dominated
512504 // block only (`curr`), and discard the overlapping portion of the `prev` span. (Note
513- // that if `prev.span` is wider than `prev_original_span `, a coverage span will still
505+ // that if `prev.span` is wider than `prev.original_span `, a coverage span will still
514506 // be created for `prev`s block, for the non-overlapping portion, left of `curr.span`.)
515507 //
516508 // For example:
0 commit comments