@@ -767,7 +767,8 @@ 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+ return res;
771772 }
772773 DefKind :: Const => { }
773774 _ => unreachable ! ( ) ,
@@ -803,10 +804,17 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
803804 tcx. ensure_ok ( ) . predicates_of ( def_id) ;
804805 tcx. ensure_ok ( ) . associated_items ( def_id) ;
805806 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+ ) ;
808811
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+ }
810818 }
811819 }
812820 DefKind :: Trait => {
@@ -884,6 +892,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
884892 tcx. ensure_ok ( ) . explicit_implied_const_bounds ( def_id) ;
885893 tcx. ensure_ok ( ) . const_conditions ( def_id) ;
886894 }
895+ return res;
887896 }
888897 DefKind :: TyAlias => {
889898 tcx. ensure_ok ( ) . generics_of ( def_id) ;
@@ -976,6 +985,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
976985 // We do not call `type_of` for closures here as that
977986 // depends on typecheck and would therefore hide
978987 // any further errors in case one typeck fails.
988+ return res;
979989 }
980990 DefKind :: AssocFn => {
981991 tcx. ensure_ok ( ) . codegen_fn_attrs ( def_id) ;
@@ -990,6 +1000,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
9901000 res = res. and ( check_trait_item ( tcx, def_id) ) ;
9911001 }
9921002 }
1003+ return res;
9931004 }
9941005 DefKind :: AssocConst => {
9951006 tcx. ensure_ok ( ) . type_of ( def_id) ;
@@ -1002,6 +1013,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10021013 res = res. and ( check_trait_item ( tcx, def_id) ) ;
10031014 }
10041015 }
1016+ return res;
10051017 }
10061018 DefKind :: AssocTy => {
10071019 tcx. ensure_ok ( ) . predicates_of ( def_id) ;
@@ -1020,10 +1032,18 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10201032 if has_type {
10211033 tcx. ensure_ok ( ) . type_of ( def_id) ;
10221034 }
1035+ return res;
10231036 }
1037+ DefKind :: AnonConst | DefKind :: InlineConst => return res,
10241038 _ => { }
10251039 }
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+ } )
10271047}
10281048
10291049pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
0 commit comments