1
1
use rustc_data_structures:: graph:: WithNumNodes ;
2
2
use rustc_index:: bit_set:: BitSet ;
3
3
use rustc_middle:: mir;
4
- use rustc_span:: { BytePos , Span , DUMMY_SP } ;
4
+ use rustc_span:: { BytePos , Span } ;
5
5
6
6
use crate :: coverage:: graph:: { BasicCoverageBlock , CoverageGraph , START_BCB } ;
7
7
use crate :: coverage:: spans:: from_mir:: SpanFromMir ;
@@ -102,7 +102,7 @@ impl CurrCovspan {
102
102
103
103
fn into_prev ( self ) -> PrevCovspan {
104
104
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 }
106
106
}
107
107
108
108
fn into_refined ( self ) -> RefinedCovspan {
@@ -115,6 +115,7 @@ impl CurrCovspan {
115
115
116
116
#[ derive( Debug ) ]
117
117
struct PrevCovspan {
118
+ original_span : Span ,
118
119
span : Span ,
119
120
bcb : BasicCoverageBlock ,
120
121
/// List of all the original spans from MIR that have been merged into this
@@ -142,12 +143,12 @@ impl PrevCovspan {
142
143
}
143
144
144
145
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 ;
146
147
DuplicateCovspan { span, bcb, is_closure }
147
148
}
148
149
149
150
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 ;
151
152
RefinedCovspan { span, bcb, is_closure }
152
153
}
153
154
@@ -217,11 +218,6 @@ struct SpansRefiner<'a> {
217
218
/// If that `curr` was discarded, `prev` retains its value from the previous iteration.
218
219
some_prev : Option < PrevCovspan > ,
219
220
220
- /// Assigned from `curr.span` from the previous iteration. The `prev_original_span`
221
- /// **must not be mutated** (except when advancing to the next `prev`), even if `prev.span()`
222
- /// is mutated.
223
- prev_original_span : Span ,
224
-
225
221
/// One or more coverage spans with the same `Span` but different `BasicCoverageBlock`s, and
226
222
/// no `BasicCoverageBlock` in this list dominates another `BasicCoverageBlock` in the list.
227
223
/// If a new `curr` span also fits this criteria (compared to an existing list of
@@ -250,7 +246,6 @@ impl<'a> SpansRefiner<'a> {
250
246
sorted_spans_iter : sorted_spans. into_iter ( ) ,
251
247
some_curr : None ,
252
248
some_prev : None ,
253
- prev_original_span : DUMMY_SP ,
254
249
pending_dups : Vec :: new ( ) ,
255
250
refined_spans : Vec :: with_capacity ( basic_coverage_blocks. num_nodes ( ) * 2 ) ,
256
251
} ;
@@ -292,7 +287,7 @@ impl<'a> SpansRefiner<'a> {
292
287
self . take_curr ( ) ; // Discards curr.
293
288
} else if curr. is_closure {
294
289
self . carve_out_span_for_closure ( ) ;
295
- } else if self . prev_original_span == curr. span {
290
+ } else if prev . original_span == curr. span {
296
291
// `prev` and `curr` have the same span, or would have had the
297
292
// same span before `prev` was modified by other spans.
298
293
self . update_pending_dups ( ) ;
@@ -392,7 +387,6 @@ impl<'a> SpansRefiner<'a> {
392
387
/// Advance `prev` to `curr` (if any), and `curr` to the next coverage span in sorted order.
393
388
fn next_coverage_span ( & mut self ) -> bool {
394
389
if let Some ( curr) = self . some_curr . take ( ) {
395
- self . prev_original_span = curr. span ;
396
390
self . some_prev = Some ( curr. into_prev ( ) ) ;
397
391
}
398
392
while let Some ( curr) = self . sorted_spans_iter . next ( ) {
@@ -445,9 +439,7 @@ impl<'a> SpansRefiner<'a> {
445
439
}
446
440
447
441
if has_post_closure_span {
448
- // Mutate `prev.span()` to start after the closure (and discard curr).
449
- // (**NEVER** update `prev_original_span` because it affects the assumptions
450
- // about how the coverage spans are ordered.)
442
+ // Mutate `prev.span` to start after the closure (and discard curr).
451
443
self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
452
444
debug ! ( " Mutated prev.span to start after the closure. prev={:?}" , self . prev( ) ) ;
453
445
@@ -464,12 +456,12 @@ impl<'a> SpansRefiner<'a> {
464
456
}
465
457
}
466
458
467
- /// Called if `curr.span` equals `prev_original_span ` (and potentially equal to all
459
+ /// Called if `curr.span` equals `prev.original_span ` (and potentially equal to all
468
460
/// `pending_dups` spans, if any). Keep in mind, `prev.span()` may have been changed.
469
461
/// If prev.span() was merged into other spans (with matching BCB, for instance),
470
- /// `prev.span.hi()` will be greater than (further right of) `prev_original_span .hi()`.
462
+ /// `prev.span.hi()` will be greater than (further right of) `prev.original_span .hi()`.
471
463
/// If prev.span() was split off to the right of a closure, prev.span().lo() will be
472
- /// greater than prev_original_span. lo(). The actual span of `prev_original_span ` is
464
+ /// greater than prev.original_span. lo(). The actual span of `prev.original_span ` is
473
465
/// not as important as knowing that `prev()` **used to have the same span** as `curr()`,
474
466
/// which means their sort order is still meaningful for determining the dominator
475
467
/// relationship.
@@ -507,7 +499,7 @@ impl<'a> SpansRefiner<'a> {
507
499
self . cutoff_prev_at_overlapping_curr ( ) ;
508
500
// If one span dominates the other, associate the span with the code from the dominated
509
501
// block only (`curr`), and discard the overlapping portion of the `prev` span. (Note
510
- // that if `prev.span` is wider than `prev_original_span `, a coverage span will still
502
+ // that if `prev.span` is wider than `prev.original_span `, a coverage span will still
511
503
// be created for `prev`s block, for the non-overlapping portion, left of `curr.span`.)
512
504
//
513
505
// For example:
0 commit comments