@@ -21,6 +21,7 @@ use rustc::ty::fold::{TypeFoldable, TypeFolder};
21
21
use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
22
22
use rustc:: ty:: { self , ToPolyTraitRef , ToPredicate , Ty , TyCtxt , WithConstness } ;
23
23
use rustc_ast:: ast:: Ident ;
24
+ use rustc_errors:: ErrorReported ;
24
25
use rustc_hir:: def_id:: DefId ;
25
26
use rustc_span:: symbol:: sym;
26
27
use rustc_span:: DUMMY_SP ;
@@ -1010,7 +1011,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1010
1011
// NOTE: This should be kept in sync with the similar code in
1011
1012
// `rustc::ty::instance::resolve_associated_item()`.
1012
1013
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 | ( ) ) ?;
1014
1016
1015
1017
let is_default = if node_item. node . is_from_trait ( ) {
1016
1018
// If true, the impl inherited a `type Foo = Bar`
@@ -1405,7 +1407,10 @@ fn confirm_impl_candidate<'cx, 'tcx>(
1405
1407
let trait_def_id = tcx. trait_id_of_impl ( impl_def_id) . unwrap ( ) ;
1406
1408
1407
1409
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
+ } ;
1409
1414
1410
1415
if !assoc_ty. item . defaultness . has_value ( ) {
1411
1416
// This means that the impl is missing a definition for the
@@ -1444,14 +1449,14 @@ fn assoc_ty_def(
1444
1449
selcx : & SelectionContext < ' _ , ' _ > ,
1445
1450
impl_def_id : DefId ,
1446
1451
assoc_ty_def_id : DefId ,
1447
- ) -> specialization_graph:: NodeItem < ty:: AssocItem > {
1452
+ ) -> Result < specialization_graph:: NodeItem < ty:: AssocItem > , ErrorReported > {
1448
1453
let tcx = selcx. tcx ( ) ;
1449
1454
let assoc_ty_name = tcx. associated_item ( assoc_ty_def_id) . ident ;
1450
1455
let trait_def_id = tcx. impl_trait_ref ( impl_def_id) . unwrap ( ) . def_id ;
1451
1456
let trait_def = tcx. trait_def ( trait_def_id) ;
1452
1457
1453
1458
// 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()),
1455
1460
// so, in order to avoid unnecessary infinite recursion, we manually look
1456
1461
// for the associated item at the given impl.
1457
1462
// If there is no such item in that impl, this function will fail with a
@@ -1461,17 +1466,16 @@ fn assoc_ty_def(
1461
1466
if matches ! ( item. kind, ty:: AssocKind :: Type | ty:: AssocKind :: OpaqueTy )
1462
1467
&& tcx. hygienic_eq ( item. ident , assoc_ty_name, trait_def_id)
1463
1468
{
1464
- return specialization_graph:: NodeItem {
1469
+ return Ok ( specialization_graph:: NodeItem {
1465
1470
node : specialization_graph:: Node :: Impl ( impl_def_id) ,
1466
1471
item : * item,
1467
- } ;
1472
+ } ) ;
1468
1473
}
1469
1474
}
1470
1475
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)
1475
1479
} else {
1476
1480
// This is saying that neither the trait nor
1477
1481
// the impl contain a definition for this
0 commit comments