coverage: Add #[track_caller] to the span generator's unwrap methods

This should make it easier to investigate unwrap failures in bug reports.
This commit is contained in:
Zalathar 2023-12-06 21:07:43 +11:00
parent e0cd8057c8
commit cec814202a

View File

@ -385,38 +385,36 @@ fn maybe_push_macro_name_span(&mut self) {
self.refined_spans.push(macro_name_cov); self.refined_spans.push(macro_name_cov);
} }
#[track_caller]
fn curr(&self) -> &CoverageSpan { fn curr(&self) -> &CoverageSpan {
self.some_curr self.some_curr.as_ref().unwrap_or_else(|| bug!("some_curr is None (curr)"))
.as_ref()
.unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_curr"))
} }
#[track_caller]
fn curr_mut(&mut self) -> &mut CoverageSpan { fn curr_mut(&mut self) -> &mut CoverageSpan {
self.some_curr self.some_curr.as_mut().unwrap_or_else(|| bug!("some_curr is None (curr_mut)"))
.as_mut()
.unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_curr"))
} }
/// If called, then the next call to `next_coverage_span()` will *not* update `prev` with the /// If called, then the next call to `next_coverage_span()` will *not* update `prev` with the
/// `curr` coverage span. /// `curr` coverage span.
#[track_caller]
fn take_curr(&mut self) -> CoverageSpan { fn take_curr(&mut self) -> CoverageSpan {
self.some_curr.take().unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_curr")) self.some_curr.take().unwrap_or_else(|| bug!("some_curr is None (take_curr)"))
} }
#[track_caller]
fn prev(&self) -> &CoverageSpan { fn prev(&self) -> &CoverageSpan {
self.some_prev self.some_prev.as_ref().unwrap_or_else(|| bug!("some_prev is None (prev)"))
.as_ref()
.unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_prev"))
} }
#[track_caller]
fn prev_mut(&mut self) -> &mut CoverageSpan { fn prev_mut(&mut self) -> &mut CoverageSpan {
self.some_prev self.some_prev.as_mut().unwrap_or_else(|| bug!("some_prev is None (prev_mut)"))
.as_mut()
.unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_prev"))
} }
#[track_caller]
fn take_prev(&mut self) -> CoverageSpan { fn take_prev(&mut self) -> CoverageSpan {
self.some_prev.take().unwrap_or_else(|| bug!("invalid attempt to unwrap a None some_prev")) self.some_prev.take().unwrap_or_else(|| bug!("some_prev is None (take_prev)"))
} }
/// If there are `pending_dups` but `prev` is not a matching dup (`prev.span` doesn't match the /// If there are `pending_dups` but `prev` is not a matching dup (`prev.span` doesn't match the