Skip to content

Commit 8c38eab

Browse files
committed
coverage: Simplify make_coverage_hir_info
1 parent 343cdd5 commit 8c38eab

File tree

1 file changed

+16
-10
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+16
-10
lines changed

compiler/rustc_mir_transform/src/coverage/mod.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -314,21 +314,27 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
314314
}
315315

316316
fn make_coverage_hir_info(tcx: TyCtxt<'_>, def_id: LocalDefId) -> mir::coverage::HirInfo {
317-
let source_map = tcx.sess.source_map();
318-
let (some_fn_sig, hir_body) = fn_sig_and_body(tcx, def_id);
317+
let (maybe_fn_sig, hir_body) = fn_sig_and_body(tcx, def_id);
319318

319+
let function_source_hash = hash_mir_source(tcx, hir_body);
320320
let body_span = get_body_span(tcx, hir_body, def_id);
321321

322-
let source_file = source_map.lookup_source_file(body_span.lo());
323-
let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
324-
fn_sig.span.eq_ctxt(body_span)
325-
&& Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.lo()))
326-
}) {
327-
Some(fn_sig) => fn_sig.span.with_hi(body_span.lo()),
328-
None => body_span.shrink_to_lo(),
322+
let spans_are_compatible = {
323+
let source_map = tcx.sess.source_map();
324+
|a: Span, b: Span| {
325+
a.eq_ctxt(b)
326+
&& source_map.lookup_source_file_idx(a.lo())
327+
== source_map.lookup_source_file_idx(b.lo())
328+
}
329329
};
330330

331-
let function_source_hash = hash_mir_source(tcx, hir_body);
331+
let fn_sig_span = if let Some(fn_sig) = maybe_fn_sig
332+
&& spans_are_compatible(fn_sig.span, body_span)
333+
{
334+
fn_sig.span.with_hi(body_span.lo())
335+
} else {
336+
body_span.shrink_to_lo()
337+
};
332338

333339
mir::coverage::HirInfo { function_source_hash, fn_sig_span, body_span }
334340
}

0 commit comments

Comments
 (0)