Skip to content

Commit 25e6303

Browse files
committed
coverage: Move take_curr and note what its callers are doing
1 parent 41038db commit 25e6303

File tree

1 file changed

+9
-9
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+9
-9
lines changed

compiler/rustc_mir_transform/src/coverage/spans.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'a> CoverageSpansGenerator<'a> {
315315
debug!(
316316
" curr overlaps a closure (prev). Drop curr and keep prev for next iter. prev={prev:?}",
317317
);
318-
self.take_curr();
318+
self.take_curr(); // Discards curr.
319319
} else if curr.is_closure {
320320
self.carve_out_span_for_closure();
321321
} else if self.prev_original_span == curr.span {
@@ -341,7 +341,7 @@ impl<'a> CoverageSpansGenerator<'a> {
341341
as prev, but is in a different bcb. Drop curr and keep prev for next iter. \
342342
prev={prev:?}",
343343
);
344-
self.take_curr();
344+
self.take_curr(); // Discards curr.
345345
} else {
346346
self.update_pending_dups();
347347
}
@@ -432,6 +432,12 @@ impl<'a> CoverageSpansGenerator<'a> {
432432
.unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_curr"))
433433
}
434434

435+
/// If called, then the next call to `next_coverage_span()` will *not* update `prev` with the
436+
/// `curr` coverage span.
437+
fn take_curr(&mut self) -> CoverageSpan {
438+
self.some_curr.take().unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_curr"))
439+
}
440+
435441
fn prev(&self) -> &CoverageSpan {
436442
self.some_prev
437443
.as_ref()
@@ -504,12 +510,6 @@ impl<'a> CoverageSpansGenerator<'a> {
504510
false
505511
}
506512

507-
/// If called, then the next call to `next_coverage_span()` will *not* update `prev` with the
508-
/// `curr` coverage span.
509-
fn take_curr(&mut self) -> CoverageSpan {
510-
self.some_curr.take().unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_curr"))
511-
}
512-
513513
/// Returns true if the curr span should be skipped because prev has already advanced beyond the
514514
/// end of curr. This can only happen if a prior iteration updated `prev` to skip past a region
515515
/// of code, such as skipping past a closure.
@@ -556,7 +556,7 @@ impl<'a> CoverageSpansGenerator<'a> {
556556
dup.span = dup.span.with_lo(right_cutoff);
557557
}
558558
self.pending_dups.append(&mut pending_dups);
559-
let closure_covspan = self.take_curr();
559+
let closure_covspan = self.take_curr(); // Prevent this curr from becoming prev.
560560
self.push_refined_span(closure_covspan); // since self.prev() was already updated
561561
} else {
562562
pending_dups.clear();

0 commit comments

Comments
 (0)