diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-09-06 07:33:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-06 07:33:59 +0200 |
| commit | 11d5614a74ba0da0aeba2848b1b13e9ab2fdee4c (patch) | |
| tree | b89acb130790e38a5958301b1b156c847912bd57 /compiler/rustc_mir_transform/src/coverage/unexpand.rs | |
| parent | 6841e354200619db603a4ac1cc6f15b47cbb16df (diff) | |
| parent | 25d183057edcf5d24ba0dcc8d5222a2a954aa80f (diff) | |
| download | rust-11d5614a74ba0da0aeba2848b1b13e9ab2fdee4c.tar.gz rust-11d5614a74ba0da0aeba2848b1b13e9ab2fdee4c.zip | |
Rollup merge of #130013 - jonathan-conder:await_coverage, r=Zalathar
coverage: Count await when the Future is immediately ready Currently `await` is only counted towards coverage if the containing function is suspended and resumed at least once. This is because it expands to code which contains a branch on the discriminant of `Poll`. By treating it like a branching macro (e.g. `assert!`), these implementation details will be hidden from the coverage results. I added a test to ensure the fix works in simple cases, but the heuristic of picking only the first await-related covspan might be unreliable. I plan on testing more thoroughly with a real codebase over the next couple of weeks. closes #98712
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/unexpand.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/unexpand.rs | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/unexpand.rs b/compiler/rustc_mir_transform/src/coverage/unexpand.rs index 8cde291b907..cb861544736 100644 --- a/compiler/rustc_mir_transform/src/coverage/unexpand.rs +++ b/compiler/rustc_mir_transform/src/coverage/unexpand.rs @@ -1,4 +1,4 @@ -use rustc_span::{ExpnKind, MacroKind, Span, Symbol}; +use rustc_span::{ExpnKind, Span}; /// Walks through the expansion ancestors of `original_span` to find a span that /// is contained in `body_span` and has the same [syntax context] as `body_span`. @@ -13,20 +13,15 @@ pub(crate) fn unexpand_into_body_span(original_span: Span, body_span: Span) -> O /// /// If the returned span represents a bang-macro invocation (e.g. `foo!(..)`), /// the returned symbol will be the name of that macro (e.g. `foo`). -pub(crate) fn unexpand_into_body_span_with_visible_macro( +pub(crate) fn unexpand_into_body_span_with_expn_kind( original_span: Span, body_span: Span, -) -> Option<(Span, Option<Symbol>)> { +) -> Option<(Span, Option<ExpnKind>)> { let (span, prev) = unexpand_into_body_span_with_prev(original_span, body_span)?; - let visible_macro = prev - .map(|prev| match prev.ctxt().outer_expn_data().kind { - ExpnKind::Macro(MacroKind::Bang, name) => Some(name), - _ => None, - }) - .flatten(); + let expn_kind = prev.map(|prev| prev.ctxt().outer_expn_data().kind); - Some((span, visible_macro)) + Some((span, expn_kind)) } /// Walks through the expansion ancestors of `original_span` to find a span that |
