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
@@ -220,11 +221,6 @@ struct SpansRefiner<'a> {
220
221
/// If that `curr` was discarded, `prev` retains its value from the previous iteration.
221
222
some_prev : Option < PrevCovspan > ,
222
223
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
-
228
224
/// One or more coverage spans with the same `Span` but different `BasicCoverageBlock`s, and
229
225
/// no `BasicCoverageBlock` in this list dominates another `BasicCoverageBlock` in the list.
230
226
/// If a new `curr` span also fits this criteria (compared to an existing list of
@@ -253,7 +249,6 @@ impl<'a> SpansRefiner<'a> {
253
249
sorted_spans_iter : sorted_spans. into_iter ( ) ,
254
250
some_curr : None ,
255
251
some_prev : None ,
256
- prev_original_span : DUMMY_SP ,
257
252
pending_dups : Vec :: new ( ) ,
258
253
refined_spans : Vec :: with_capacity ( basic_coverage_blocks. num_nodes ( ) * 2 ) ,
259
254
} ;
@@ -295,7 +290,7 @@ impl<'a> SpansRefiner<'a> {
295
290
self . take_curr ( ) ; // Discards curr.
296
291
} else if curr. is_closure {
297
292
self . carve_out_span_for_closure ( ) ;
298
- } else if self . prev_original_span == curr. span {
293
+ } else if prev . original_span == curr. span {
299
294
// `prev` and `curr` have the same span, or would have had the
300
295
// same span before `prev` was modified by other spans.
301
296
self . update_pending_dups ( ) ;
@@ -395,7 +390,6 @@ impl<'a> SpansRefiner<'a> {
395
390
/// Advance `prev` to `curr` (if any), and `curr` to the next coverage span in sorted order.
396
391
fn next_coverage_span ( & mut self ) -> bool {
397
392
if let Some ( curr) = self . some_curr . take ( ) {
398
- self . prev_original_span = curr. span ;
399
393
self . some_prev = Some ( curr. into_prev ( ) ) ;
400
394
}
401
395
while let Some ( curr) = self . sorted_spans_iter . next ( ) {
@@ -448,9 +442,7 @@ impl<'a> SpansRefiner<'a> {
448
442
}
449
443
450
444
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).
454
446
self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
455
447
debug ! ( " Mutated prev.span to start after the closure. prev={:?}" , self . prev( ) ) ;
456
448
@@ -467,12 +459,12 @@ impl<'a> SpansRefiner<'a> {
467
459
}
468
460
}
469
461
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
471
463
/// `pending_dups` spans, if any). Keep in mind, `prev.span()` may have been changed.
472
464
/// 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()`.
474
466
/// 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
476
468
/// not as important as knowing that `prev()` **used to have the same span** as `curr()`,
477
469
/// which means their sort order is still meaningful for determining the dominator
478
470
/// relationship.
@@ -510,7 +502,7 @@ impl<'a> SpansRefiner<'a> {
510
502
self . cutoff_prev_at_overlapping_curr ( ) ;
511
503
// If one span dominates the other, associate the span with the code from the dominated
512
504
// 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
514
506
// be created for `prev`s block, for the non-overlapping portion, left of `curr.span`.)
515
507
//
516
508
// For example:
0 commit comments