about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/coverage/mod.rs
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-12-14 12:58:10 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-12-15 10:59:32 +1100
commit7de2156bfda6a2c443486a7d469a56c75284e320 (patch)
treea2755ccdbb445b88a32655c069050fcc379ade3f /compiler/rustc_mir_transform/src/coverage/mod.rs
parente2f449bcc975464d8cabf24ea6fe3219037ea361 (diff)
downloadrust-7de2156bfda6a2c443486a7d469a56c75284e320.tar.gz
rust-7de2156bfda6a2c443486a7d469a56c75284e320.zip
coverage: Inline and simplify `fn_sig_and_body`
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/mod.rs')
-rw-r--r--compiler/rustc_mir_transform/src/coverage/mod.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs
index d7fdde209bd..76a23fdccd4 100644
--- a/compiler/rustc_mir_transform/src/coverage/mod.rs
+++ b/compiler/rustc_mir_transform/src/coverage/mod.rs
@@ -314,13 +314,20 @@ struct ExtractedHirInfo {
 }
 
 fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHirInfo {
+    // FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
+    // to HIR for it.
+
     let source_map = tcx.sess.source_map();
-    let (some_fn_sig, hir_body) = fn_sig_and_body(tcx, def_id);
+
+    let hir_node = tcx.hir_node_by_def_id(def_id);
+    let (_, fn_body_id) =
+        hir::map::associated_body(hir_node).expect("HIR node is a function with body");
+    let hir_body = tcx.hir().body(fn_body_id);
 
     let body_span = get_body_span(tcx, hir_body, def_id);
 
     let source_file = source_map.lookup_source_file(body_span.lo());
-    let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
+    let fn_sig_span = match hir_node.fn_sig().filter(|fn_sig| {
         fn_sig.span.eq_ctxt(body_span)
             && Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.lo()))
     }) {
@@ -333,18 +340,6 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
     ExtractedHirInfo { function_source_hash, fn_sig_span, body_span }
 }
 
-fn fn_sig_and_body(
-    tcx: TyCtxt<'_>,
-    def_id: LocalDefId,
-) -> (Option<&rustc_hir::FnSig<'_>>, &rustc_hir::Body<'_>) {
-    // FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
-    // to HIR for it.
-    let hir_node = tcx.hir_node_by_def_id(def_id);
-    let (_, fn_body_id) =
-        hir::map::associated_body(hir_node).expect("HIR node is a function with body");
-    (hir_node.fn_sig(), tcx.hir().body(fn_body_id))
-}
-
 fn get_body_span<'tcx>(
     tcx: TyCtxt<'tcx>,
     hir_body: &rustc_hir::Body<'tcx>,