Skip to content

Commit 077c95c

Browse files
committed
!! (WIP) track the enclosing ! expression
1 parent 04a32fc commit 077c95c

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

compiler/rustc_mir_build/src/build/coverageinfo.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_middle::hir;
22
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
33
use rustc_middle::mir::coverage::{BlockMarkerId, BranchSpan, CoverageKind};
44
use rustc_middle::mir::{self, BasicBlock, SourceInfo, Statement, StatementKind};
5+
use rustc_middle::thir::Expr;
56
use rustc_middle::ty::TyCtxt;
67
use rustc_span::def_id::LocalDefId;
78
use rustc_span::{ExpnKind, Span, DUMMY_SP};
@@ -151,6 +152,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
151152
pub(crate) fn coverage_add_branch(
152153
&mut self,
153154
cond_source_info: SourceInfo,
155+
enclosing_not_expr: Option<&Expr<'tcx>>,
154156
then_blk: &mut BasicBlock,
155157
else_blk: &mut BasicBlock,
156158
) {
@@ -174,13 +176,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
174176
id
175177
};
176178

177-
let true_marker = inject_branch_marker(then_blk);
178-
let false_marker = inject_branch_marker(else_blk);
179+
let mut span = cond_source_info.span;
180+
let mut true_marker = inject_branch_marker(then_blk);
181+
let mut false_marker = inject_branch_marker(else_blk);
179182

180-
hir_info_builder.branch_spans.push(BranchSpan {
181-
span: cond_source_info.span,
182-
true_marker,
183-
false_marker,
184-
});
183+
if let Some(enclosing_not_expr) = enclosing_not_expr {
184+
span = enclosing_not_expr.span;
185+
std::mem::swap(&mut true_marker, &mut false_marker);
186+
}
187+
188+
hir_info_builder.branch_spans.push(BranchSpan { span, true_marker, false_marker });
185189
}
186190
}

compiler/rustc_mir_build/src/build/matches/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4444
self.then_else_break_inner(
4545
block,
4646
expr,
47+
None,
4748
temp_scope_override,
4849
break_scope,
4950
variable_source_info,
@@ -54,6 +55,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5455
&mut self,
5556
mut block: BasicBlock,
5657
expr: &Expr<'tcx>,
58+
enclosing_not_expr: Option<&Expr<'tcx>>, // Only used by coverage instrumentation
5759
temp_scope_override: Option<region::Scope>,
5860
break_scope: region::Scope,
5961
variable_source_info: SourceInfo,
@@ -107,9 +109,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
107109
let local_scope = this.local_scope();
108110
let (success_block, failure_block) =
109111
this.in_if_then_scope(local_scope, expr_span, |this| {
110-
this.then_else_break(
112+
this.then_else_break_inner(
111113
block,
112114
&this.thir[arg],
115+
Some(expr),
113116
temp_scope_override,
114117
local_scope,
115118
variable_source_info,
@@ -121,9 +124,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
121124
ExprKind::Scope { region_scope, lint_level, value } => {
122125
let region_scope = (region_scope, this.source_info(expr_span));
123126
this.in_scope(region_scope, lint_level, |this| {
124-
this.then_else_break(
127+
this.then_else_break_inner(
125128
block,
126129
&this.thir[value],
130+
enclosing_not_expr,
127131
temp_scope_override,
128132
break_scope,
129133
variable_source_info,
@@ -162,7 +166,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
162166
if let Some(coverage) = &this.coverage
163167
&& coverage.branch_coverage_enabled
164168
{
165-
this.coverage_add_branch(source_info, &mut then_block, &mut else_block);
169+
this.coverage_add_branch(
170+
source_info,
171+
enclosing_not_expr,
172+
&mut then_block,
173+
&mut else_block,
174+
);
166175
}
167176

168177
this.cfg.terminate(block, source_info, term);

0 commit comments

Comments
 (0)