diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2023-12-22 14:11:42 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2024-01-05 12:53:23 +1100 |
| commit | 506b9f96893a56159334f05d85500313a783f199 (patch) | |
| tree | 2e1d9b85d9d8221cc3d68dda8fbc771c4f4d7eaa /compiler | |
| parent | f688dd684faca5b31b156fac2c6e0ae81fc9bc90 (diff) | |
| download | rust-506b9f96893a56159334f05d85500313a783f199.tar.gz rust-506b9f96893a56159334f05d85500313a783f199.zip | |
coverage: Avoid early returns from `mir_to_initial_sorted_coverage_spans`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs index 8f6592afe85..913819ef33d 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs @@ -15,27 +15,26 @@ pub(super) fn mir_to_initial_sorted_coverage_spans( basic_coverage_blocks: &CoverageGraph, ) -> Vec<CoverageSpan> { let &ExtractedHirInfo { is_async_fn, fn_sig_span, body_span, .. } = hir_info; + + let mut initial_spans = vec![CoverageSpan::for_fn_sig(fn_sig_span)]; + if is_async_fn { // An async function desugars into a function that returns a future, // with the user code wrapped in a closure. Any spans in the desugared - // outer function will be unhelpful, so just produce a single span - // associating the function signature with its entry BCB. - return vec![CoverageSpan::for_fn_sig(fn_sig_span)]; - } - - let mut initial_spans = Vec::with_capacity(mir_body.basic_blocks.len() * 2); - for (bcb, bcb_data) in basic_coverage_blocks.iter_enumerated() { - initial_spans.extend(bcb_to_initial_coverage_spans(mir_body, body_span, bcb, bcb_data)); - } + // outer function will be unhelpful, so just keep the signature span + // and ignore all of the spans in the MIR body. + } else { + for (bcb, bcb_data) in basic_coverage_blocks.iter_enumerated() { + initial_spans.extend(bcb_to_initial_coverage_spans(mir_body, body_span, bcb, bcb_data)); + } - if initial_spans.is_empty() { - // This can happen if, for example, the function is unreachable (contains only a - // `BasicBlock`(s) with an `Unreachable` terminator). - return initial_spans; + // If no spans were extracted from the body, discard the signature span. + // FIXME: This preserves existing behavior; consider getting rid of it. + if initial_spans.len() == 1 { + initial_spans.clear(); + } } - initial_spans.push(CoverageSpan::for_fn_sig(fn_sig_span)); - initial_spans.sort_by(|a, b| { // First sort by span start. Ord::cmp(&a.span.lo(), &b.span.lo()) |
