coverage: Use SpanMarker
to mark the full condition of if !
When MIR is built for an if-not expression, the `!` part of the condition doesn't correspond to any MIR statement, so coverage instrumentation normally can't see it. We can fix that by deliberately injecting a dummy statement whose sole purpose is to associate that span with its enclosing block.
This commit is contained in:
parent
98166358a9
commit
d90fd027c8
5 changed files with 17 additions and 12 deletions
|
@ -90,6 +90,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let local_scope = this.local_scope();
|
||||
let (success_block, failure_block) =
|
||||
this.in_if_then_scope(local_scope, expr_span, |this| {
|
||||
// Help out coverage instrumentation by injecting a dummy statement with
|
||||
// the original condition's span (including `!`). This fixes #115468.
|
||||
if this.tcx.sess.instrument_coverage() {
|
||||
this.cfg.push_coverage_span_marker(block, this.source_info(expr_span));
|
||||
}
|
||||
this.then_else_break(
|
||||
block,
|
||||
&this.thir[arg],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue