@@ -21,6 +21,7 @@ use rustc::ty::fold::{TypeFoldable, TypeFolder};
2121use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
2222use rustc:: ty:: { self , ToPolyTraitRef , ToPredicate , Ty , TyCtxt , WithConstness } ;
2323use rustc_ast:: ast:: Ident ;
24+ use rustc_errors:: ErrorReported ;
2425use rustc_hir:: def_id:: DefId ;
2526use rustc_span:: symbol:: sym;
2627use rustc_span:: DUMMY_SP ;
@@ -1010,7 +1011,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
10101011 // NOTE: This should be kept in sync with the similar code in
10111012 // `rustc::ty::instance::resolve_associated_item()`.
10121013 let node_item =
1013- assoc_ty_def ( selcx, impl_data. impl_def_id , obligation. predicate . item_def_id ) ;
1014+ assoc_ty_def ( selcx, impl_data. impl_def_id , obligation. predicate . item_def_id )
1015+ . map_err ( |ErrorReported | ( ) ) ?;
10141016
10151017 let is_default = if node_item. node . is_from_trait ( ) {
10161018 // If true, the impl inherited a `type Foo = Bar`
@@ -1405,7 +1407,10 @@ fn confirm_impl_candidate<'cx, 'tcx>(
14051407 let trait_def_id = tcx. trait_id_of_impl ( impl_def_id) . unwrap ( ) ;
14061408
14071409 let param_env = obligation. param_env ;
1408- let assoc_ty = assoc_ty_def ( selcx, impl_def_id, assoc_item_id) ;
1410+ let assoc_ty = match assoc_ty_def ( selcx, impl_def_id, assoc_item_id) {
1411+ Ok ( assoc_ty) => assoc_ty,
1412+ Err ( ErrorReported ) => return Progress { ty : tcx. types . err , obligations : nested } ,
1413+ } ;
14091414
14101415 if !assoc_ty. item . defaultness . has_value ( ) {
14111416 // This means that the impl is missing a definition for the
@@ -1444,14 +1449,14 @@ fn assoc_ty_def(
14441449 selcx : & SelectionContext < ' _ , ' _ > ,
14451450 impl_def_id : DefId ,
14461451 assoc_ty_def_id : DefId ,
1447- ) -> specialization_graph:: NodeItem < ty:: AssocItem > {
1452+ ) -> Result < specialization_graph:: NodeItem < ty:: AssocItem > , ErrorReported > {
14481453 let tcx = selcx. tcx ( ) ;
14491454 let assoc_ty_name = tcx. associated_item ( assoc_ty_def_id) . ident ;
14501455 let trait_def_id = tcx. impl_trait_ref ( impl_def_id) . unwrap ( ) . def_id ;
14511456 let trait_def = tcx. trait_def ( trait_def_id) ;
14521457
14531458 // This function may be called while we are still building the
1454- // specialization graph that is queried below (via TraidDef ::ancestors()),
1459+ // specialization graph that is queried below (via TraitDef ::ancestors()),
14551460 // so, in order to avoid unnecessary infinite recursion, we manually look
14561461 // for the associated item at the given impl.
14571462 // If there is no such item in that impl, this function will fail with a
@@ -1461,17 +1466,16 @@ fn assoc_ty_def(
14611466 if matches ! ( item. kind, ty:: AssocKind :: Type | ty:: AssocKind :: OpaqueTy )
14621467 && tcx. hygienic_eq ( item. ident , assoc_ty_name, trait_def_id)
14631468 {
1464- return specialization_graph:: NodeItem {
1469+ return Ok ( specialization_graph:: NodeItem {
14651470 node : specialization_graph:: Node :: Impl ( impl_def_id) ,
14661471 item : * item,
1467- } ;
1472+ } ) ;
14681473 }
14691474 }
14701475
1471- if let Some ( assoc_item) =
1472- trait_def. ancestors ( tcx, impl_def_id) . leaf_def ( tcx, assoc_ty_name, ty:: AssocKind :: Type )
1473- {
1474- assoc_item
1476+ let ancestors = trait_def. ancestors ( tcx, impl_def_id) ?;
1477+ if let Some ( assoc_item) = ancestors. leaf_def ( tcx, assoc_ty_name, ty:: AssocKind :: Type ) {
1478+ Ok ( assoc_item)
14751479 } else {
14761480 // This is saying that neither the trait nor
14771481 // the impl contain a definition for this
0 commit comments