Skip to content

Commit 7de2156

Browse files
committed
coverage: Inline and simplify fn_sig_and_body
1 parent e2f449b commit 7de2156

File tree

1 file changed

+9
-14
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+9
-14
lines changed

compiler/rustc_mir_transform/src/coverage/mod.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,20 @@ struct ExtractedHirInfo {
314314
}
315315

316316
fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHirInfo {
317+
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
318+
// to HIR for it.
319+
317320
let source_map = tcx.sess.source_map();
318-
let (some_fn_sig, hir_body) = fn_sig_and_body(tcx, def_id);
321+
322+
let hir_node = tcx.hir_node_by_def_id(def_id);
323+
let (_, fn_body_id) =
324+
hir::map::associated_body(hir_node).expect("HIR node is a function with body");
325+
let hir_body = tcx.hir().body(fn_body_id);
319326

320327
let body_span = get_body_span(tcx, hir_body, def_id);
321328

322329
let source_file = source_map.lookup_source_file(body_span.lo());
323-
let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
330+
let fn_sig_span = match hir_node.fn_sig().filter(|fn_sig| {
324331
fn_sig.span.eq_ctxt(body_span)
325332
&& Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.lo()))
326333
}) {
@@ -333,18 +340,6 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
333340
ExtractedHirInfo { function_source_hash, fn_sig_span, body_span }
334341
}
335342

336-
fn fn_sig_and_body(
337-
tcx: TyCtxt<'_>,
338-
def_id: LocalDefId,
339-
) -> (Option<&rustc_hir::FnSig<'_>>, &rustc_hir::Body<'_>) {
340-
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
341-
// to HIR for it.
342-
let hir_node = tcx.hir_node_by_def_id(def_id);
343-
let (_, fn_body_id) =
344-
hir::map::associated_body(hir_node).expect("HIR node is a function with body");
345-
(hir_node.fn_sig(), tcx.hir().body(fn_body_id))
346-
}
347-
348343
fn get_body_span<'tcx>(
349344
tcx: TyCtxt<'tcx>,
350345
hir_body: &rustc_hir::Body<'tcx>,

0 commit comments

Comments
 (0)