Skip to content

Commit b72c472

Browse files
committed
coverage: Inline and simplify fn_sig_and_body
1 parent b253c78 commit b72c472

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,20 @@ struct ExtractedHirInfo {
303303
}
304304

305305
fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHirInfo {
306+
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
307+
// to HIR for it.
308+
306309
let source_map = tcx.sess.source_map();
307-
let (some_fn_sig, hir_body) = fn_sig_and_body(tcx, def_id);
310+
311+
let hir_node = tcx.hir_node_by_def_id(def_id);
312+
let (_, fn_body_id) =
313+
hir::map::associated_body(hir_node).expect("HIR node is a function with body");
314+
let hir_body = tcx.hir().body(fn_body_id);
308315

309316
let body_span = get_body_span(tcx, hir_body, def_id);
310317

311318
let source_file = source_map.lookup_source_file(body_span.lo());
312-
let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
319+
let fn_sig_span = match hir_node.fn_sig().filter(|fn_sig| {
313320
fn_sig.span.eq_ctxt(body_span)
314321
&& Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.lo()))
315322
}) {
@@ -322,18 +329,6 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
322329
ExtractedHirInfo { function_source_hash, fn_sig_span, body_span }
323330
}
324331

325-
fn fn_sig_and_body(
326-
tcx: TyCtxt<'_>,
327-
def_id: LocalDefId,
328-
) -> (Option<&rustc_hir::FnSig<'_>>, &rustc_hir::Body<'_>) {
329-
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
330-
// to HIR for it.
331-
let hir_node = tcx.hir_node_by_def_id(def_id);
332-
let (_, fn_body_id) =
333-
hir::map::associated_body(hir_node).expect("HIR node is a function with body");
334-
(hir_node.fn_sig(), tcx.hir().body(fn_body_id))
335-
}
336-
337332
fn get_body_span<'tcx>(
338333
tcx: TyCtxt<'tcx>,
339334
hir_body: &rustc_hir::Body<'tcx>,

0 commit comments

Comments
 (0)