@@ -53,7 +53,7 @@ use rustc_const_eval::{eval_const_expr_partial, ConstEvalErr};
5353use rustc_const_eval:: EvalHint :: UncheckedExprHint ;
5454use rustc_const_eval:: ErrKind :: ErroneousReferencedConstant ;
5555use hir:: { self , SelfKind } ;
56- use hir:: def:: { self , Def } ;
56+ use hir:: def:: { Def , PathResolution } ;
5757use hir:: def_id:: DefId ;
5858use hir:: print as pprust;
5959use middle:: resolve_lifetime as rl;
@@ -1327,7 +1327,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
13271327 } ;
13281328
13291329 if self . ensure_super_predicates ( span, trait_did) . is_err ( ) {
1330- return ( tcx. types . err , ty_path_def ) ;
1330+ return ( tcx. types . err , Def :: Err ) ;
13311331 }
13321332
13331333 let candidates: Vec < ty:: PolyTraitRef > =
@@ -1341,7 +1341,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
13411341 & assoc_name. as_str ( ) ,
13421342 span) {
13431343 Ok ( bound) => bound,
1344- Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def ) ,
1344+ Err ( ErrorReported ) => return ( tcx. types . err , Def :: Err ) ,
13451345 }
13461346 }
13471347 ( & ty:: TyParam ( _) , Def :: SelfTy ( Some ( trait_did) , None ) ) => {
@@ -1351,7 +1351,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
13511351 assoc_name,
13521352 span) {
13531353 Ok ( bound) => bound,
1354- Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def ) ,
1354+ Err ( ErrorReported ) => return ( tcx. types . err , Def :: Err ) ,
13551355 }
13561356 }
13571357 ( & ty:: TyParam ( _) , Def :: TyParam ( _, _, param_did, param_name) ) => {
@@ -1361,15 +1361,15 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
13611361 assoc_name,
13621362 span) {
13631363 Ok ( bound) => bound,
1364- Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def ) ,
1364+ Err ( ErrorReported ) => return ( tcx. types . err , Def :: Err ) ,
13651365 }
13661366 }
13671367 _ => {
13681368 self . report_ambiguous_associated_type ( span,
13691369 & ty. to_string ( ) ,
13701370 "Trait" ,
13711371 & assoc_name. as_str ( ) ) ;
1372- return ( tcx. types . err , ty_path_def ) ;
1372+ return ( tcx. types . err , Def :: Err ) ;
13731373 }
13741374 } ;
13751375
@@ -1574,45 +1574,46 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
15741574 }
15751575 }
15761576
1577- // Note that both base_segments and assoc_segments may be empty, although not at
1578- // the same time.
1577+ // Resolve possibly associated type path into a type and final definition.
1578+ // Note that both base_segments and assoc_segments may be empty, although not at same time.
15791579 pub fn finish_resolving_def_to_ty ( & self ,
15801580 rscope : & RegionScope ,
15811581 span : Span ,
15821582 param_mode : PathParamMode ,
1583- mut def : Def ,
1583+ base_def : Def ,
15841584 opt_self_ty : Option < Ty < ' tcx > > ,
15851585 base_path_ref_id : ast:: NodeId ,
15861586 base_segments : & [ hir:: PathSegment ] ,
15871587 assoc_segments : & [ hir:: PathSegment ] )
15881588 -> ( Ty < ' tcx > , Def ) {
1589- debug ! ( "finish_resolving_def_to_ty(def={:?}, \
1589+ // Convert the base type.
1590+ debug ! ( "finish_resolving_def_to_ty(base_def={:?}, \
15901591 base_segments={:?}, \
15911592 assoc_segments={:?})",
1592- def ,
1593+ base_def ,
15931594 base_segments,
15941595 assoc_segments) ;
1595- let mut ty = self . base_def_to_ty ( rscope,
1596- span,
1597- param_mode,
1598- def,
1599- opt_self_ty,
1600- base_path_ref_id,
1601- base_segments) ;
1602- debug ! ( "finish_resolving_def_to_ty: base_def_to_ty returned {:?}" , ty) ;
1596+ let base_ty = self . base_def_to_ty ( rscope,
1597+ span,
1598+ param_mode,
1599+ base_def,
1600+ opt_self_ty,
1601+ base_path_ref_id,
1602+ base_segments) ;
1603+ debug ! ( "finish_resolving_def_to_ty: base_def_to_ty returned {:?}" , base_ty) ;
1604+
16031605 // If any associated type segments remain, attempt to resolve them.
1606+ let ( mut ty, mut def) = ( base_ty, base_def) ;
16041607 for segment in assoc_segments {
16051608 debug ! ( "finish_resolving_def_to_ty: segment={:?}" , segment) ;
1606- if ty. sty == ty:: TyError {
1609+ // This is pretty bad (it will fail except for T::A and Self::A).
1610+ let ( new_ty, new_def) = self . associated_path_def_to_ty ( span, ty, def, segment) ;
1611+ ty = new_ty;
1612+ def = new_def;
1613+
1614+ if def == Def :: Err {
16071615 break ;
16081616 }
1609- // This is pretty bad (it will fail except for T::A and Self::A).
1610- let ( a_ty, a_def) = self . associated_path_def_to_ty ( span,
1611- ty,
1612- def,
1613- segment) ;
1614- ty = a_ty;
1615- def = a_def;
16161617 }
16171618 ( ty, def)
16181619 }
@@ -1719,23 +1720,22 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
17191720 hir:: TyPath ( ref maybe_qself, ref path) => {
17201721 debug ! ( "ast_ty_to_ty: maybe_qself={:?} path={:?}" , maybe_qself, path) ;
17211722 let path_res = tcx. expect_resolution ( ast_ty. id ) ;
1722- let def = path_res. base_def ;
17231723 let base_ty_end = path. segments . len ( ) - path_res. depth ;
17241724 let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| {
17251725 self . ast_ty_to_ty ( rscope, & qself. ty )
17261726 } ) ;
1727- let ( ty, _def ) = self . finish_resolving_def_to_ty ( rscope,
1728- ast_ty. span ,
1729- PathParamMode :: Explicit ,
1730- def ,
1731- opt_self_ty,
1732- ast_ty. id ,
1733- & path. segments [ ..base_ty_end] ,
1734- & path. segments [ base_ty_end..] ) ;
1735-
1736- if path_res . depth != 0 && ty . sty != ty :: TyError {
1737- // Write back the new resolution.
1738- tcx. def_map . borrow_mut ( ) . insert ( ast_ty. id , def :: PathResolution :: new ( def) ) ;
1727+ let ( ty, def ) = self . finish_resolving_def_to_ty ( rscope,
1728+ ast_ty. span ,
1729+ PathParamMode :: Explicit ,
1730+ path_res . base_def ,
1731+ opt_self_ty,
1732+ ast_ty. id ,
1733+ & path. segments [ ..base_ty_end] ,
1734+ & path. segments [ base_ty_end..] ) ;
1735+
1736+ // Write back the new resolution.
1737+ if path_res . depth != 0 {
1738+ tcx. def_map . borrow_mut ( ) . insert ( ast_ty. id , PathResolution :: new ( def) ) ;
17391739 }
17401740
17411741 ty
0 commit comments