compute fn_sig span from body call_site, and use body ctxt, not root

This commit is contained in:
Rich Kadel 2021-04-19 12:30:55 -07:00
parent 1893721ec4
commit 5d8d67f746
2 changed files with 10 additions and 5 deletions

View File

@ -11,7 +11,7 @@ use rustc_middle::mir::{
use rustc_middle::ty::TyCtxt;
use rustc_span::source_map::original_sp;
use rustc_span::{BytePos, Span, SyntaxContext};
use rustc_span::{BytePos, Span};
use std::cmp::Ordering;
@ -246,8 +246,8 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
) -> Vec<CoverageSpan> {
let mut coverage_spans = CoverageSpans {
mir_body,
fn_sig_span: fn_sig_span.with_ctxt(SyntaxContext::root()),
body_span: body_span.with_ctxt(SyntaxContext::root()),
fn_sig_span: fn_sig_source_span(fn_sig_span, body_span),
body_span,
basic_coverage_blocks,
sorted_spans_iter: None,
refined_spans: Vec::with_capacity(basic_coverage_blocks.num_nodes() * 2),
@ -731,8 +731,13 @@ pub(super) fn filtered_terminator_span(
}
}
#[inline]
fn fn_sig_source_span(fn_sig_span: Span, body_span: Span) -> Span {
original_sp(fn_sig_span, body_span).with_ctxt(body_span.ctxt())
}
#[inline]
fn function_source_span(span: Span, body_span: Span) -> Span {
let span = original_sp(span, body_span).with_ctxt(SyntaxContext::root());
let span = original_sp(span, body_span).with_ctxt(body_span.ctxt());
if body_span.contains(span) { span } else { body_span }
}

View File

@ -2,7 +2,7 @@
2| |// structure of this test.
3| |
4| 2|#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
^0 ^0 ^0 ^1 ^0
^0 ^0 ^0 ^0 ^1 ^1 ^0^0
------------------
| Unexecuted instantiation: <partial_eq::Version as core::cmp::PartialEq>::ne
------------------