about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/check/wfcheck.rs
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-06-13 09:10:04 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-06-30 08:45:43 +0000
commit70215dfe61b277fb9bb19590dd1fa6754d9c1bd1 (patch)
treec529a909f34d54f4f35a4ff9765d3345b5af97a9 /compiler/rustc_hir_analysis/src/check/wfcheck.rs
parent5940109a0403ec55e7b922256e6e6f82d0c100a2 (diff)
downloadrust-70215dfe61b277fb9bb19590dd1fa6754d9c1bd1.tar.gz
rust-70215dfe61b277fb9bb19590dd1fa6754d9c1bd1.zip
Avoid eagerly loading the hir fn sig
Diffstat (limited to 'compiler/rustc_hir_analysis/src/check/wfcheck.rs')
-rw-r--r--compiler/rustc_hir_analysis/src/check/wfcheck.rs25
1 files changed, 11 insertions, 14 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs
index f03b860ec78..846e1315e9a 100644
--- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs
+++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs
@@ -328,16 +328,15 @@ fn check_trait_item<'tcx>(
 ) -> Result<(), ErrorGuaranteed> {
     let def_id = trait_item.owner_id.def_id;
 
-    let (method_sig, span) = match trait_item.kind {
-        hir::TraitItemKind::Fn(ref sig, _) => (Some(sig), trait_item.span),
-        hir::TraitItemKind::Type(_bounds, Some(ty)) => (None, ty.span),
-        _ => (None, trait_item.span),
+    let span = match trait_item.kind {
+        hir::TraitItemKind::Type(_bounds, Some(ty)) => ty.span,
+        _ => trait_item.span,
     };
 
     // Check that an item definition in a subtrait is shadowing a supertrait item.
     lint_item_shadowing_supertrait_item(tcx, def_id);
 
-    let mut res = check_associated_item(tcx, def_id, span, method_sig);
+    let mut res = check_associated_item(tcx, def_id, span);
 
     if matches!(trait_item.kind, hir::TraitItemKind::Fn(..)) {
         for &assoc_ty_def_id in tcx.associated_types_for_impl_traits_in_associated_fn(def_id) {
@@ -345,7 +344,6 @@ fn check_trait_item<'tcx>(
                 tcx,
                 assoc_ty_def_id.expect_local(),
                 tcx.def_span(assoc_ty_def_id),
-                None,
             ));
         }
     }
@@ -829,13 +827,12 @@ fn check_impl_item<'tcx>(
     tcx: TyCtxt<'tcx>,
     impl_item: &'tcx hir::ImplItem<'tcx>,
 ) -> Result<(), ErrorGuaranteed> {
-    let (method_sig, span) = match impl_item.kind {
-        hir::ImplItemKind::Fn(ref sig, _) => (Some(sig), impl_item.span),
+    let span = match impl_item.kind {
         // Constrain binding and overflow error spans to `<Ty>` in `type foo = <Ty>`.
-        hir::ImplItemKind::Type(ty) if ty.span != DUMMY_SP => (None, ty.span),
-        _ => (None, impl_item.span),
+        hir::ImplItemKind::Type(ty) if ty.span != DUMMY_SP => ty.span,
+        _ => impl_item.span,
     };
-    check_associated_item(tcx, impl_item.owner_id.def_id, span, method_sig)
+    check_associated_item(tcx, impl_item.owner_id.def_id, span)
 }
 
 fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), ErrorGuaranteed> {
@@ -963,12 +960,11 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er
     }
 }
 
-#[instrument(level = "debug", skip(tcx, span, sig_if_method))]
+#[instrument(level = "debug", skip(tcx, span))]
 fn check_associated_item(
     tcx: TyCtxt<'_>,
     item_id: LocalDefId,
     span: Span,
-    sig_if_method: Option<&hir::FnSig<'_>>,
 ) -> Result<(), ErrorGuaranteed> {
     let loc = Some(WellFormedLoc::Ty(item_id));
     enter_wf_checking_ctxt(tcx, item_id, |wfcx| {
@@ -1002,7 +998,8 @@ fn check_associated_item(
             }
             ty::AssocKind::Fn { .. } => {
                 let sig = tcx.fn_sig(item.def_id).instantiate_identity();
-                let hir_sig = sig_if_method.expect("bad signature for method");
+                let hir_sig =
+                    tcx.hir_node_by_def_id(item_id).fn_sig().expect("bad signature for method");
                 check_fn_or_method(wfcx, sig, hir_sig.decl, item.def_id.expect_local());
                 check_method_receiver(wfcx, hir_sig, item, self_ty)
             }