@@ -283,43 +283,48 @@ impl<'a> CoverageSpansGenerator<'a> {
283
283
/// de-duplicated `CoverageSpan`s.
284
284
fn to_refined_spans ( mut self ) -> Vec < CoverageSpan > {
285
285
while self . next_coverage_span ( ) {
286
+ // For the first span we don't have `prev` set, so most of the
287
+ // span-processing steps don't make sense yet.
286
288
if self . some_prev . is_none ( ) {
287
289
debug ! ( " initial span" ) ;
288
290
self . check_invoked_macro_name_span ( ) ;
289
- } else if self . curr ( ) . is_mergeable ( self . prev ( ) ) {
290
- debug ! ( " same bcb (and neither is a closure), merge with prev={:?}" , self . prev( ) ) ;
291
+ continue ;
292
+ }
293
+
294
+ // The remaining cases assume that `prev` and `curr` are set.
295
+ let prev = self . prev ( ) ;
296
+ let curr = self . curr ( ) ;
297
+
298
+ if curr. is_mergeable ( prev) {
299
+ debug ! ( " same bcb (and neither is a closure), merge with prev={prev:?}" ) ;
291
300
let prev = self . take_prev ( ) ;
292
301
self . curr_mut ( ) . merge_from ( prev) ;
293
302
self . check_invoked_macro_name_span ( ) ;
294
303
// Note that curr.span may now differ from curr_original_span
295
- } else if self . prev_ends_before_curr ( ) {
304
+ } else if prev . span . hi ( ) <= curr . span . lo ( ) {
296
305
debug ! (
297
- " different bcbs and disjoint spans, so keep curr for next iter, and add \
298
- prev={:?}",
299
- self . prev( )
306
+ " different bcbs and disjoint spans, so keep curr for next iter, and add prev={prev:?}" ,
300
307
) ;
301
308
let prev = self . take_prev ( ) ;
302
309
self . push_refined_span ( prev) ;
303
310
self . check_invoked_macro_name_span ( ) ;
304
- } else if self . prev ( ) . is_closure {
311
+ } else if prev. is_closure {
305
312
// drop any equal or overlapping span (`curr`) and keep `prev` to test again in the
306
313
// next iter
307
314
debug ! (
308
- " curr overlaps a closure (prev). Drop curr and keep prev for next iter. \
309
- prev={:?}",
310
- self . prev( )
315
+ " curr overlaps a closure (prev). Drop curr and keep prev for next iter. prev={prev:?}" ,
311
316
) ;
312
317
self . take_curr ( ) ;
313
- } else if self . curr ( ) . is_closure {
318
+ } else if curr. is_closure {
314
319
self . carve_out_span_for_closure ( ) ;
315
- } else if self . prev_original_span == self . curr ( ) . span {
320
+ } else if self . prev_original_span == curr. span {
316
321
// Note that this compares the new (`curr`) span to `prev_original_span`.
317
322
// In this branch, the actual span byte range of `prev_original_span` is not
318
323
// important. What is important is knowing whether the new `curr` span was
319
324
// **originally** the same as the original span of `prev()`. The original spans
320
325
// reflect their original sort order, and for equal spans, conveys a partial
321
326
// ordering based on CFG dominator priority.
322
- if self . prev ( ) . is_macro_expansion ( ) && self . curr ( ) . is_macro_expansion ( ) {
327
+ if prev. is_macro_expansion ( ) && curr. is_macro_expansion ( ) {
323
328
// Macros that expand to include branching (such as
324
329
// `assert_eq!()`, `assert_ne!()`, `info!()`, `debug!()`, or
325
330
// `trace!()`) typically generate callee spans with identical
@@ -333,8 +338,7 @@ impl<'a> CoverageSpansGenerator<'a> {
333
338
debug ! (
334
339
" curr and prev are part of a macro expansion, and curr has the same span \
335
340
as prev, but is in a different bcb. Drop curr and keep prev for next iter. \
336
- prev={:?}",
337
- self . prev( )
341
+ prev={prev:?}",
338
342
) ;
339
343
self . take_curr ( ) ;
340
344
} else {
@@ -346,8 +350,8 @@ impl<'a> CoverageSpansGenerator<'a> {
346
350
}
347
351
}
348
352
349
- debug ! ( " AT END, adding last prev={:?}" , self . prev( ) ) ;
350
353
let prev = self . take_prev ( ) ;
354
+ debug ! ( " AT END, adding last prev={prev:?}" ) ;
351
355
let pending_dups = self . pending_dups . split_off ( 0 ) ;
352
356
for dup in pending_dups {
353
357
debug ! ( " ...adding at least one pending dup={:?}" , dup) ;
@@ -504,12 +508,6 @@ impl<'a> CoverageSpansGenerator<'a> {
504
508
self . prev ( ) . span . lo ( ) > next_curr. span . lo ( )
505
509
}
506
510
507
- /// Returns true if the curr span starts past the end of the prev span, which means they don't
508
- /// overlap, so we now know the prev can be added to the refined coverage spans.
509
- fn prev_ends_before_curr ( & self ) -> bool {
510
- self . prev ( ) . span . hi ( ) <= self . curr ( ) . span . lo ( )
511
- }
512
-
513
511
/// If `prev`s span extends left of the closure (`curr`), carve out the closure's span from
514
512
/// `prev`'s span. (The closure's coverage counters will be injected when processing the
515
513
/// closure's own MIR.) Add the portion of the span to the left of the closure; and if the span
0 commit comments