about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/coverage/spans
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-12-06 18:40:06 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-12-08 22:49:11 +1100
commite0cd8057c85260e827e417cfcf3c6c861d2c8426 (patch)
treecf48230c1ee3020d351acaf22c1e6f0782a38d9b /compiler/rustc_mir_transform/src/coverage/spans
parent5ea62560f294947e55b0cf895dae23fe3c41777c (diff)
coverage: Simplify the heuristic for ignoring `async fn` return spans
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/spans')
-rw-r--r--compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs10
1 files changed, 10 insertions, 0 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 e1531f2c239..b850b3374ba 100644
--- a/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs
+++ b/compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs
@@ -44,6 +44,16 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
             .then_with(|| Ord::cmp(&a.is_closure, &b.is_closure).reverse())
     });
 
+    // The desugaring of an async function includes a closure containing the
+    // original function body, and a terminator that returns the `impl Future`.
+    // That terminator will cause a confusing coverage count for the function's
+    // closing brace, so discard everything after the body closure span.
+    if let Some(body_closure_index) =
+        initial_spans.iter().rposition(|covspan| covspan.is_closure && covspan.span == body_span)
+    {
+        initial_spans.truncate(body_closure_index + 1);
+    }
+
     initial_spans
 }