Skip to content

Commit 5d8d67f

Browse files
committed
compute fn_sig span from body call_site, and use body ctxt, not root
1 parent 1893721 commit 5d8d67f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

compiler/rustc_mir/src/transform/coverage/spans.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir::{
1111
use rustc_middle::ty::TyCtxt;
1212

1313
use rustc_span::source_map::original_sp;
14-
use rustc_span::{BytePos, Span, SyntaxContext};
14+
use rustc_span::{BytePos, Span};
1515

1616
use std::cmp::Ordering;
1717

@@ -246,8 +246,8 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
246246
) -> Vec<CoverageSpan> {
247247
let mut coverage_spans = CoverageSpans {
248248
mir_body,
249-
fn_sig_span: fn_sig_span.with_ctxt(SyntaxContext::root()),
250-
body_span: body_span.with_ctxt(SyntaxContext::root()),
249+
fn_sig_span: fn_sig_source_span(fn_sig_span, body_span),
250+
body_span,
251251
basic_coverage_blocks,
252252
sorted_spans_iter: None,
253253
refined_spans: Vec::with_capacity(basic_coverage_blocks.num_nodes() * 2),
@@ -731,8 +731,13 @@ pub(super) fn filtered_terminator_span(
731731
}
732732
}
733733

734+
#[inline]
735+
fn fn_sig_source_span(fn_sig_span: Span, body_span: Span) -> Span {
736+
original_sp(fn_sig_span, body_span).with_ctxt(body_span.ctxt())
737+
}
738+
734739
#[inline]
735740
fn function_source_span(span: Span, body_span: Span) -> Span {
736-
let span = original_sp(span, body_span).with_ctxt(SyntaxContext::root());
741+
let span = original_sp(span, body_span).with_ctxt(body_span.ctxt());
737742
if body_span.contains(span) { span } else { body_span }
738743
}

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.partial_eq.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
2| |// structure of this test.
33
3| |
44
4| 2|#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
5-
^0 ^0 ^0 ^1 ^0
5+
^0 ^0 ^0 ^0 ^1 ^1 ^0^0
66
------------------
77
| Unexecuted instantiation: <partial_eq::Version as core::cmp::PartialEq>::ne
88
------------------

0 commit comments

Comments
 (0)