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