Skip to content

Commit

Permalink
Fix ICE if original_span(fn_sig) returns a span not in body sourcefile
Browse files Browse the repository at this point in the history
  • Loading branch information
richkadel committed Apr 22, 2021
1 parent ccf1712 commit a07bf2e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_mir/src/transform/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
let body_span = hir_body.value.span;
let source_file = source_map.lookup_source_file(body_span.lo());
let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.hi()))
fn_sig.span.ctxt() == body_span.ctxt()
&& Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.hi()))
}) {
Some(fn_sig) => fn_sig.span.with_hi(body_span.lo()),
None => body_span.shrink_to_lo(),
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_mir/src/transform/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
/// to be).
pub(super) fn generate_coverage_spans(
mir_body: &'a mir::Body<'tcx>,
fn_sig_span: Span,
fn_sig_span: Span, // Ensured to be same SourceFile and SyntaxContext as `body_span`
body_span: Span,
basic_coverage_blocks: &'a CoverageGraph,
) -> Vec<CoverageSpan> {
let mut coverage_spans = CoverageSpans {
mir_body,
fn_sig_span: fn_sig_source_span(fn_sig_span, body_span),
fn_sig_span,
body_span,
basic_coverage_blocks,
sorted_spans_iter: None,
Expand Down Expand Up @@ -731,11 +731,6 @@ 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(body_span.ctxt());
Expand Down

0 comments on commit a07bf2e

Please sign in to comment.