@@ -767,7 +767,12 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
767767                DefKind :: Static  {  .. }  => { 
768768                    check_static_inhabited ( tcx,  def_id) ; 
769769                    check_static_linkage ( tcx,  def_id) ; 
770-                     wfcheck:: check_static_item ( tcx,  def_id) ?; 
770+                     res = res. and ( wfcheck:: check_static_item ( tcx,  def_id) ) ; 
771+ 
772+                     // Only `Node::Item` and `Node::ForeignItem` still have HIR based 
773+                     // checks. Returning early here does not miss any checks and 
774+                     // avoids this query from having a direct dependency edge on the HIR 
775+                     return  res; 
771776                } 
772777                DefKind :: Const  => { } 
773778                _ => unreachable ! ( ) , 
@@ -803,10 +808,17 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
803808            tcx. ensure_ok ( ) . predicates_of ( def_id) ; 
804809            tcx. ensure_ok ( ) . associated_items ( def_id) ; 
805810            if  of_trait && let  Some ( impl_trait_header)  = tcx. impl_trait_header ( def_id)  { 
806-                 tcx. ensure_ok ( ) 
807-                     . coherent_trait ( impl_trait_header. trait_ref . instantiate_identity ( ) . def_id ) ?; 
811+                 res = res. and ( 
812+                     tcx. ensure_ok ( ) 
813+                         . coherent_trait ( impl_trait_header. trait_ref . instantiate_identity ( ) . def_id ) , 
814+                 ) ; 
808815
809-                 check_impl_items_against_trait ( tcx,  def_id,  impl_trait_header) ; 
816+                 if  res. is_ok ( )  { 
817+                     // Checking this only makes sense if the all trait impls satisfy basic 
818+                     // requirements (see `coherent_trait` query), otherwise 
819+                     // we run into infinite recursions a lot. 
820+                     check_impl_items_against_trait ( tcx,  def_id,  impl_trait_header) ; 
821+                 } 
810822            } 
811823        } 
812824        DefKind :: Trait  => { 
@@ -884,6 +896,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
884896                tcx. ensure_ok ( ) . explicit_implied_const_bounds ( def_id) ; 
885897                tcx. ensure_ok ( ) . const_conditions ( def_id) ; 
886898            } 
899+ 
900+             // Only `Node::Item` and `Node::ForeignItem` still have HIR based 
901+             // checks. Returning early here does not miss any checks and 
902+             // avoids this query from having a direct dependency edge on the HIR 
903+             return  res; 
887904        } 
888905        DefKind :: TyAlias  => { 
889906            tcx. ensure_ok ( ) . generics_of ( def_id) ; 
@@ -976,6 +993,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
976993            // We do not call `type_of` for closures here as that 
977994            // depends on typecheck and would therefore hide 
978995            // any further errors in case one typeck fails. 
996+ 
997+             // Only `Node::Item` and `Node::ForeignItem` still have HIR based 
998+             // checks. Returning early here does not miss any checks and 
999+             // avoids this query from having a direct dependency edge on the HIR 
1000+             return  res; 
9791001        } 
9801002        DefKind :: AssocFn  => { 
9811003            tcx. ensure_ok ( ) . codegen_fn_attrs ( def_id) ; 
@@ -990,6 +1012,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
9901012                    res = res. and ( check_trait_item ( tcx,  def_id) ) ; 
9911013                } 
9921014            } 
1015+ 
1016+             // Only `Node::Item` and `Node::ForeignItem` still have HIR based 
1017+             // checks. Returning early here does not miss any checks and 
1018+             // avoids this query from having a direct dependency edge on the HIR 
1019+             return  res; 
9931020        } 
9941021        DefKind :: AssocConst  => { 
9951022            tcx. ensure_ok ( ) . type_of ( def_id) ; 
@@ -1002,6 +1029,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10021029                    res = res. and ( check_trait_item ( tcx,  def_id) ) ; 
10031030                } 
10041031            } 
1032+ 
1033+             // Only `Node::Item` and `Node::ForeignItem` still have HIR based 
1034+             // checks. Returning early here does not miss any checks and 
1035+             // avoids this query from having a direct dependency edge on the HIR 
1036+             return  res; 
10051037        } 
10061038        DefKind :: AssocTy  => { 
10071039            tcx. ensure_ok ( ) . predicates_of ( def_id) ; 
@@ -1020,10 +1052,26 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10201052            if  has_type { 
10211053                tcx. ensure_ok ( ) . type_of ( def_id) ; 
10221054            } 
1055+ 
1056+             // Only `Node::Item` and `Node::ForeignItem` still have HIR based 
1057+             // checks. Returning early here does not miss any checks and 
1058+             // avoids this query from having a direct dependency edge on the HIR 
1059+             return  res; 
10231060        } 
1061+ 
1062+         // Only `Node::Item` and `Node::ForeignItem` still have HIR based 
1063+         // checks. Returning early here does not miss any checks and 
1064+         // avoids this query from having a direct dependency edge on the HIR 
1065+         DefKind :: AnonConst  | DefKind :: InlineConst  => return  res, 
10241066        _ => { } 
10251067    } 
1026-     res
1068+     let  node = tcx. hir_node_by_def_id ( def_id) ; 
1069+     res. and ( match  node { 
1070+         hir:: Node :: Crate ( _)  => bug ! ( "check_well_formed cannot be applied to the crate root" ) , 
1071+         hir:: Node :: Item ( item)  => wfcheck:: check_item ( tcx,  item) , 
1072+         hir:: Node :: ForeignItem ( item)  => wfcheck:: check_foreign_item ( tcx,  item) , 
1073+         _ => unreachable ! ( "{node:?}" ) , 
1074+     } ) 
10271075} 
10281076
10291077pub ( super )  fn  check_on_unimplemented ( tcx :  TyCtxt < ' _ > ,  def_id :  LocalDefId )  { 
0 commit comments