Skip to content

Commit 684b9ea

Browse files
committed
coverage: Check that the function signature span precedes the body
This will normally be true, but in cases where it's not true we're better off not making any assumptions about the signature.
1 parent 3b610c7 commit 684b9ea

File tree

1 file changed

+4
-2
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+4
-2
lines changed

compiler/rustc_mir_transform/src/coverage/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,16 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
324324
let body_span = get_body_span(tcx, hir_body, def_id);
325325

326326
// The actual signature span is only used if it has the same context and
327-
// filename as the body.
327+
// filename as the body, and precedes the body.
328328
let maybe_fn_sig_span = hir_node.fn_sig().map(|fn_sig| fn_sig.span);
329329
let fn_sig_span = maybe_fn_sig_span
330330
.filter(|&fn_sig_span| {
331331
let source_map = tcx.sess.source_map();
332332
let file_idx = |span: Span| source_map.lookup_source_file_idx(span.lo());
333333

334-
fn_sig_span.eq_ctxt(body_span) && file_idx(fn_sig_span) == file_idx(body_span)
334+
fn_sig_span.eq_ctxt(body_span)
335+
&& fn_sig_span.hi() <= body_span.lo()
336+
&& file_idx(fn_sig_span) == file_idx(body_span)
335337
})
336338
// If so, extend it to the start of the body span.
337339
.map(|fn_sig_span| fn_sig_span.with_hi(body_span.lo()))

0 commit comments

Comments
 (0)