@@ -767,7 +767,8 @@ 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
+ return res;
771
772
}
772
773
DefKind :: Const => { }
773
774
_ => unreachable ! ( ) ,
@@ -803,10 +804,17 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
803
804
tcx. ensure_ok ( ) . predicates_of ( def_id) ;
804
805
tcx. ensure_ok ( ) . associated_items ( def_id) ;
805
806
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 ) ?;
807
+ res = res. and (
808
+ tcx. ensure_ok ( )
809
+ . coherent_trait ( impl_trait_header. trait_ref . instantiate_identity ( ) . def_id ) ,
810
+ ) ;
808
811
809
- check_impl_items_against_trait ( tcx, def_id, impl_trait_header) ;
812
+ if res. is_ok ( ) {
813
+ // Checking this only makes sense if the all trait impls satisfy basic
814
+ // requirements (see `coherent_trait` query), otherwise
815
+ // we run into infinite recursions a lot.
816
+ check_impl_items_against_trait ( tcx, def_id, impl_trait_header) ;
817
+ }
810
818
}
811
819
}
812
820
DefKind :: Trait => {
@@ -884,6 +892,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
884
892
tcx. ensure_ok ( ) . explicit_implied_const_bounds ( def_id) ;
885
893
tcx. ensure_ok ( ) . const_conditions ( def_id) ;
886
894
}
895
+ return res;
887
896
}
888
897
DefKind :: TyAlias => {
889
898
tcx. ensure_ok ( ) . generics_of ( def_id) ;
@@ -976,6 +985,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
976
985
// We do not call `type_of` for closures here as that
977
986
// depends on typecheck and would therefore hide
978
987
// any further errors in case one typeck fails.
988
+ return res;
979
989
}
980
990
DefKind :: AssocFn => {
981
991
tcx. ensure_ok ( ) . codegen_fn_attrs ( def_id) ;
@@ -990,6 +1000,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
990
1000
res = res. and ( check_trait_item ( tcx, def_id) ) ;
991
1001
}
992
1002
}
1003
+ return res;
993
1004
}
994
1005
DefKind :: AssocConst => {
995
1006
tcx. ensure_ok ( ) . type_of ( def_id) ;
@@ -1002,6 +1013,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
1002
1013
res = res. and ( check_trait_item ( tcx, def_id) ) ;
1003
1014
}
1004
1015
}
1016
+ return res;
1005
1017
}
1006
1018
DefKind :: AssocTy => {
1007
1019
tcx. ensure_ok ( ) . predicates_of ( def_id) ;
@@ -1020,10 +1032,18 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
1020
1032
if has_type {
1021
1033
tcx. ensure_ok ( ) . type_of ( def_id) ;
1022
1034
}
1035
+ return res;
1023
1036
}
1037
+ DefKind :: AnonConst | DefKind :: InlineConst => return res,
1024
1038
_ => { }
1025
1039
}
1026
- res
1040
+ let node = tcx. hir_node_by_def_id ( def_id) ;
1041
+ res. and ( match node {
1042
+ hir:: Node :: Crate ( _) => bug ! ( "check_well_formed cannot be applied to the crate root" ) ,
1043
+ hir:: Node :: Item ( item) => wfcheck:: check_item ( tcx, item) ,
1044
+ hir:: Node :: ForeignItem ( item) => wfcheck:: check_foreign_item ( tcx, item) ,
1045
+ _ => unreachable ! ( "{node:?}" ) ,
1046
+ } )
1027
1047
}
1028
1048
1029
1049
pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
0 commit comments