@@ -283,43 +283,48 @@ impl<'a> CoverageSpansGenerator<'a> {
283283 /// de-duplicated `CoverageSpan`s.
284284 fn to_refined_spans ( mut self ) -> Vec < CoverageSpan > {
285285 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.
286288 if self . some_prev . is_none ( ) {
287289 debug ! ( " initial span" ) ;
288290 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:?}" ) ;
291300 let prev = self . take_prev ( ) ;
292301 self . curr_mut ( ) . merge_from ( prev) ;
293302 self . check_invoked_macro_name_span ( ) ;
294303 // 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 ( ) {
296305 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:?}" ,
300307 ) ;
301308 let prev = self . take_prev ( ) ;
302309 self . push_refined_span ( prev) ;
303310 self . check_invoked_macro_name_span ( ) ;
304- } else if self . prev ( ) . is_closure {
311+ } else if prev. is_closure {
305312 // drop any equal or overlapping span (`curr`) and keep `prev` to test again in the
306313 // next iter
307314 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:?}" ,
311316 ) ;
312317 self . take_curr ( ) ;
313- } else if self . curr ( ) . is_closure {
318+ } else if curr. is_closure {
314319 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 {
316321 // Note that this compares the new (`curr`) span to `prev_original_span`.
317322 // In this branch, the actual span byte range of `prev_original_span` is not
318323 // important. What is important is knowing whether the new `curr` span was
319324 // **originally** the same as the original span of `prev()`. The original spans
320325 // reflect their original sort order, and for equal spans, conveys a partial
321326 // 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 ( ) {
323328 // Macros that expand to include branching (such as
324329 // `assert_eq!()`, `assert_ne!()`, `info!()`, `debug!()`, or
325330 // `trace!()`) typically generate callee spans with identical
@@ -333,8 +338,7 @@ impl<'a> CoverageSpansGenerator<'a> {
333338 debug ! (
334339 " curr and prev are part of a macro expansion, and curr has the same span \
335340 as prev, but is in a different bcb. Drop curr and keep prev for next iter. \
336- prev={:?}",
337- self . prev( )
341+ prev={prev:?}",
338342 ) ;
339343 self . take_curr ( ) ;
340344 } else {
@@ -346,8 +350,8 @@ impl<'a> CoverageSpansGenerator<'a> {
346350 }
347351 }
348352
349- debug ! ( " AT END, adding last prev={:?}" , self . prev( ) ) ;
350353 let prev = self . take_prev ( ) ;
354+ debug ! ( " AT END, adding last prev={prev:?}" ) ;
351355 let pending_dups = self . pending_dups . split_off ( 0 ) ;
352356 for dup in pending_dups {
353357 debug ! ( " ...adding at least one pending dup={:?}" , dup) ;
@@ -506,12 +510,6 @@ impl<'a> CoverageSpansGenerator<'a> {
506510 self . prev ( ) . span . lo ( ) > next_curr. span . lo ( )
507511 }
508512
509- /// Returns true if the curr span starts past the end of the prev span, which means they don't
510- /// overlap, so we now know the prev can be added to the refined coverage spans.
511- fn prev_ends_before_curr ( & self ) -> bool {
512- self . prev ( ) . span . hi ( ) <= self . curr ( ) . span . lo ( )
513- }
514-
515513 /// If `prev`s span extends left of the closure (`curr`), carve out the closure's span from
516514 /// `prev`'s span. (The closure's coverage counters will be injected when processing the
517515 /// closure's own MIR.) Add the portion of the span to the left of the closure; and if the span
0 commit comments