Skip to content

Commit 075f9c4

Browse files
committed
coverage: Eagerly ensure that span refinement has an expansion tree node
This also replaces `push_covspan` with a separate covspan-filtering step, because the relevant code is being reindented anyway.
1 parent c783871 commit 075f9c4

File tree

1 file changed

+23
-21
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+23
-21
lines changed

compiler/rustc_mir_transform/src/coverage/spans.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,32 @@ pub(super) fn extract_refined_covspans<'tcx>(
2929

3030
let &ExtractedHirInfo { body_span, .. } = hir_info;
3131

32+
// If there somehow isn't an expansion tree node corresponding to the
33+
// body span, return now and don't create any mappings.
34+
let Some(node) = expn_tree.get(body_span.ctxt().outer_expn()) else { return };
35+
3236
let mut covspans = vec![];
33-
let mut push_covspan = |covspan: Covspan| {
37+
38+
for &SpanWithBcb { span, bcb } in &node.spans {
39+
covspans.push(Covspan { span, bcb });
40+
}
41+
42+
// For each expansion with its call-site in the body span, try to
43+
// distill a corresponding covspan.
44+
for &child_expn_id in &node.child_expn_ids {
45+
if let Some(covspan) = single_covspan_for_child_expn(tcx, graph, &expn_tree, child_expn_id)
46+
{
47+
covspans.push(covspan);
48+
}
49+
}
50+
51+
covspans.retain(|covspan: &Covspan| {
3452
let covspan_span = covspan.span;
3553
// Discard any spans not contained within the function body span.
3654
// Also discard any spans that fill the entire body, because they tend
3755
// to represent compiler-inserted code, e.g. implicitly returning `()`.
3856
if !body_span.contains(covspan_span) || body_span.source_equal(covspan_span) {
39-
return;
57+
return false;
4058
}
4159

4260
// Each pushed covspan should have the same context as the body span.
@@ -46,27 +64,11 @@ pub(super) fn extract_refined_covspans<'tcx>(
4664
false,
4765
"span context mismatch: body_span={body_span:?}, covspan.span={covspan_span:?}"
4866
);
49-
return;
50-
}
51-
52-
covspans.push(covspan);
53-
};
54-
55-
if let Some(node) = expn_tree.get(body_span.ctxt().outer_expn()) {
56-
for &SpanWithBcb { span, bcb } in &node.spans {
57-
push_covspan(Covspan { span, bcb });
67+
return false;
5868
}
5969

60-
// For each expansion with its call-site in the body span, try to
61-
// distill a corresponding covspan.
62-
for &child_expn_id in &node.child_expn_ids {
63-
if let Some(covspan) =
64-
single_covspan_for_child_expn(tcx, graph, &expn_tree, child_expn_id)
65-
{
66-
push_covspan(covspan);
67-
}
68-
}
69-
}
70+
true
71+
});
7072

7173
// Only proceed if we found at least one usable span.
7274
if covspans.is_empty() {

0 commit comments

Comments
 (0)