@@ -767,7 +767,12 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
767
767
DefKind :: Static { .. } => {
768
768
check_static_inhabited ( tcx, def_id) ;
769
769
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;
771
776
}
772
777
DefKind :: Const => { }
773
778
_ => unreachable ! ( ) ,
@@ -803,10 +808,17 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
803
808
tcx. ensure_ok ( ) . predicates_of ( def_id) ;
804
809
tcx. ensure_ok ( ) . associated_items ( def_id) ;
805
810
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
+ ) ;
808
815
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
+ }
810
822
}
811
823
}
812
824
DefKind :: Trait => {
@@ -884,6 +896,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
884
896
tcx. ensure_ok ( ) . explicit_implied_const_bounds ( def_id) ;
885
897
tcx. ensure_ok ( ) . const_conditions ( def_id) ;
886
898
}
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;
887
904
}
888
905
DefKind :: TyAlias => {
889
906
tcx. ensure_ok ( ) . generics_of ( def_id) ;
@@ -976,6 +993,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
976
993
// We do not call `type_of` for closures here as that
977
994
// depends on typecheck and would therefore hide
978
995
// 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;
979
1001
}
980
1002
DefKind :: AssocFn => {
981
1003
tcx. ensure_ok ( ) . codegen_fn_attrs ( def_id) ;
@@ -990,6 +1012,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
990
1012
res = res. and ( check_trait_item ( tcx, def_id) ) ;
991
1013
}
992
1014
}
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;
993
1020
}
994
1021
DefKind :: AssocConst => {
995
1022
tcx. ensure_ok ( ) . type_of ( def_id) ;
@@ -1002,6 +1029,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
1002
1029
res = res. and ( check_trait_item ( tcx, def_id) ) ;
1003
1030
}
1004
1031
}
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;
1005
1037
}
1006
1038
DefKind :: AssocTy => {
1007
1039
tcx. ensure_ok ( ) . predicates_of ( def_id) ;
@@ -1020,10 +1052,26 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
1020
1052
if has_type {
1021
1053
tcx. ensure_ok ( ) . type_of ( def_id) ;
1022
1054
}
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;
1023
1060
}
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,
1024
1066
_ => { }
1025
1067
}
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
+ } )
1027
1075
}
1028
1076
1029
1077
pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
0 commit comments