Skip to content

Commit 464dee2

Browse files
committed
coverage: Build up initial spans by appending to a vector
This is less elegant than returning an iterator, but more flexible.
1 parent 9c931c0 commit 464dee2

File tree

1 file changed

+21
-18
lines changed
  • compiler/rustc_mir_transform/src/coverage/spans

1 file changed

+21
-18
lines changed

compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_data_structures::captures::Captures;
21
use rustc_data_structures::fx::FxHashSet;
32
use rustc_middle::bug;
43
use rustc_middle::mir::coverage::CoverageKind;
@@ -29,7 +28,7 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
2928
let mut initial_spans = vec![];
3029

3130
for (bcb, bcb_data) in basic_coverage_blocks.iter_enumerated() {
32-
initial_spans.extend(bcb_to_initial_coverage_spans(mir_body, body_span, bcb, bcb_data));
31+
bcb_to_initial_coverage_spans(mir_body, body_span, bcb, bcb_data, &mut initial_spans);
3332
}
3433

3534
// Only add the signature span if we found at least one span in the body.
@@ -135,8 +134,9 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>(
135134
body_span: Span,
136135
bcb: BasicCoverageBlock,
137136
bcb_data: &'a BasicCoverageBlockData,
138-
) -> impl Iterator<Item = SpanFromMir> + Captures<'a> + Captures<'tcx> {
139-
bcb_data.basic_blocks.iter().flat_map(move |&bb| {
137+
initial_covspans: &mut Vec<SpanFromMir>,
138+
) {
139+
for &bb in &bcb_data.basic_blocks {
140140
let data = &mir_body[bb];
141141

142142
let unexpand = move |expn_span| {
@@ -146,24 +146,27 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>(
146146
.filter(|(span, _)| !span.source_equal(body_span))
147147
};
148148

149-
let statement_spans = data.statements.iter().filter_map(move |statement| {
150-
let expn_span = filtered_statement_span(statement)?;
151-
let (span, visible_macro) = unexpand(expn_span)?;
152-
153-
// A statement that looks like the assignment of a closure expression
154-
// is treated as a "hole" span, to be carved out of other spans.
155-
Some(SpanFromMir::new(span, visible_macro, bcb, is_closure_like(statement)))
156-
});
149+
for statement in data.statements.iter() {
150+
let _: Option<()> = try {
151+
let expn_span = filtered_statement_span(statement)?;
152+
let (span, visible_macro) = unexpand(expn_span)?;
153+
154+
// A statement that looks like the assignment of a closure expression
155+
// is treated as a "hole" span, to be carved out of other spans.
156+
let covspan =
157+
SpanFromMir::new(span, visible_macro, bcb, is_closure_like(statement));
158+
initial_covspans.push(covspan);
159+
};
160+
}
157161

158-
let terminator_span = Some(data.terminator()).into_iter().filter_map(move |terminator| {
162+
let _: Option<()> = try {
163+
let terminator = data.terminator();
159164
let expn_span = filtered_terminator_span(terminator)?;
160165
let (span, visible_macro) = unexpand(expn_span)?;
161166

162-
Some(SpanFromMir::new(span, visible_macro, bcb, false))
163-
});
164-
165-
statement_spans.chain(terminator_span)
166-
})
167+
initial_covspans.push(SpanFromMir::new(span, visible_macro, bcb, false));
168+
};
169+
}
167170
}
168171

169172
fn is_closure_like(statement: &Statement<'_>) -> bool {

0 commit comments

Comments
 (0)