Skip to content

Commit fb39d3e

Browse files
committed
coverage: Push async special case down into extract_refined_covspans
1 parent 51e62a0 commit fb39d3e

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

compiler/rustc_mir_transform/src/coverage/mappings.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::ty::TyCtxt;
1010
use rustc_span::Span;
1111

1212
use crate::coverage::ExtractedHirInfo;
13-
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, START_BCB};
13+
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph};
1414
use crate::coverage::spans::extract_refined_covspans;
1515
use crate::coverage::unexpand::unexpand_into_body_span;
1616
use crate::errors::MCDCExceedsTestVectorLimit;
@@ -82,18 +82,8 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
8282
let mut mcdc_degraded_branches = vec![];
8383
let mut mcdc_mappings = vec![];
8484

85-
if hir_info.is_async_fn {
86-
// An async function desugars into a function that returns a future,
87-
// with the user code wrapped in a closure. Any spans in the desugared
88-
// outer function will be unhelpful, so just keep the signature span
89-
// and ignore all of the spans in the MIR body.
90-
if let Some(span) = hir_info.fn_sig_span {
91-
code_mappings.push(CodeMapping { span, bcb: START_BCB });
92-
}
93-
} else {
94-
// Extract coverage spans from MIR statements/terminators as normal.
95-
extract_refined_covspans(tcx, mir_body, hir_info, graph, &mut code_mappings);
96-
}
85+
// Extract ordinary code mappings from MIR statement/terminator spans.
86+
extract_refined_covspans(tcx, mir_body, hir_info, graph, &mut code_mappings);
9787

9888
branch_pairs.extend(extract_branch_pairs(mir_body, hir_info, graph));
9989

compiler/rustc_mir_transform/src/coverage/spans.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_data_structures::fx::FxHashSet;
22
use rustc_middle::mir;
3+
use rustc_middle::mir::coverage::START_BCB;
34
use rustc_middle::ty::TyCtxt;
45
use rustc_span::source_map::SourceMap;
56
use rustc_span::{BytePos, DesugaringKind, ExpnKind, MacroKind, Span};
@@ -16,8 +17,19 @@ pub(super) fn extract_refined_covspans<'tcx>(
1617
mir_body: &mir::Body<'tcx>,
1718
hir_info: &ExtractedHirInfo,
1819
graph: &CoverageGraph,
19-
code_mappings: &mut impl Extend<mappings::CodeMapping>,
20+
code_mappings: &mut Vec<mappings::CodeMapping>,
2021
) {
22+
if hir_info.is_async_fn {
23+
// An async function desugars into a function that returns a future,
24+
// with the user code wrapped in a closure. Any spans in the desugared
25+
// outer function will be unhelpful, so just keep the signature span
26+
// and ignore all of the spans in the MIR body.
27+
if let Some(span) = hir_info.fn_sig_span {
28+
code_mappings.push(mappings::CodeMapping { span, bcb: START_BCB });
29+
}
30+
return;
31+
}
32+
2133
let &ExtractedHirInfo { body_span, .. } = hir_info;
2234

2335
let raw_spans = from_mir::extract_raw_spans_from_mir(mir_body, graph);

0 commit comments

Comments
 (0)