coverage: When merging spans, keep prev and merge curr into it

Swapping the direction of this merge produces the same results, but means that
we never need to mutate `curr`.
This commit is contained in:
Zalathar 2024-02-13 12:27:31 +11:00
parent fd9bb7fdde
commit 412c86cf03

View File

@ -221,11 +221,10 @@ impl<'a> SpansRefiner<'a> {
let prev = self.prev();
let curr = self.curr();
if curr.is_mergeable(prev) {
if prev.is_mergeable(curr) {
debug!(" same bcb (and neither is a closure), merge with prev={prev:?}");
let prev = self.take_prev();
self.curr_mut().merge_from(&prev);
// Note that curr.span may now differ from curr_original_span
let curr = self.take_curr();
self.prev_mut().merge_from(&curr);
} else if prev.span.hi() <= curr.span.lo() {
debug!(
" different bcbs and disjoint spans, so keep curr for next iter, and add prev={prev:?}",
@ -286,11 +285,6 @@ impl<'a> SpansRefiner<'a> {
self.some_curr.as_ref().unwrap_or_else(|| bug!("some_curr is None (curr)"))
}
#[track_caller]
fn curr_mut(&mut self) -> &mut CoverageSpan {
self.some_curr.as_mut().unwrap_or_else(|| bug!("some_curr is None (curr_mut)"))
}
/// If called, then the next call to `next_coverage_span()` will *not* update `prev` with the
/// `curr` coverage span.
#[track_caller]