@@ -53,7 +53,7 @@ use rustc_const_eval::{eval_const_expr_partial, ConstEvalErr};
53
53
use rustc_const_eval:: EvalHint :: UncheckedExprHint ;
54
54
use rustc_const_eval:: ErrKind :: ErroneousReferencedConstant ;
55
55
use hir:: { self , SelfKind } ;
56
- use hir:: def:: { self , Def } ;
56
+ use hir:: def:: { Def , PathResolution } ;
57
57
use hir:: def_id:: DefId ;
58
58
use hir:: print as pprust;
59
59
use middle:: resolve_lifetime as rl;
@@ -1327,7 +1327,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1327
1327
} ;
1328
1328
1329
1329
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 ) ;
1331
1331
}
1332
1332
1333
1333
let candidates: Vec < ty:: PolyTraitRef > =
@@ -1341,7 +1341,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1341
1341
& assoc_name. as_str ( ) ,
1342
1342
span) {
1343
1343
Ok ( bound) => bound,
1344
- Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def ) ,
1344
+ Err ( ErrorReported ) => return ( tcx. types . err , Def :: Err ) ,
1345
1345
}
1346
1346
}
1347
1347
( & ty:: TyParam ( _) , Def :: SelfTy ( Some ( trait_did) , None ) ) => {
@@ -1351,7 +1351,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1351
1351
assoc_name,
1352
1352
span) {
1353
1353
Ok ( bound) => bound,
1354
- Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def ) ,
1354
+ Err ( ErrorReported ) => return ( tcx. types . err , Def :: Err ) ,
1355
1355
}
1356
1356
}
1357
1357
( & ty:: TyParam ( _) , Def :: TyParam ( _, _, param_did, param_name) ) => {
@@ -1361,15 +1361,15 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1361
1361
assoc_name,
1362
1362
span) {
1363
1363
Ok ( bound) => bound,
1364
- Err ( ErrorReported ) => return ( tcx. types . err , ty_path_def ) ,
1364
+ Err ( ErrorReported ) => return ( tcx. types . err , Def :: Err ) ,
1365
1365
}
1366
1366
}
1367
1367
_ => {
1368
1368
self . report_ambiguous_associated_type ( span,
1369
1369
& ty. to_string ( ) ,
1370
1370
"Trait" ,
1371
1371
& assoc_name. as_str ( ) ) ;
1372
- return ( tcx. types . err , ty_path_def ) ;
1372
+ return ( tcx. types . err , Def :: Err ) ;
1373
1373
}
1374
1374
} ;
1375
1375
@@ -1574,45 +1574,46 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1574
1574
}
1575
1575
}
1576
1576
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.
1579
1579
pub fn finish_resolving_def_to_ty ( & self ,
1580
1580
rscope : & RegionScope ,
1581
1581
span : Span ,
1582
1582
param_mode : PathParamMode ,
1583
- mut def : Def ,
1583
+ base_def : Def ,
1584
1584
opt_self_ty : Option < Ty < ' tcx > > ,
1585
1585
base_path_ref_id : ast:: NodeId ,
1586
1586
base_segments : & [ hir:: PathSegment ] ,
1587
1587
assoc_segments : & [ hir:: PathSegment ] )
1588
1588
-> ( 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={:?}, \
1590
1591
base_segments={:?}, \
1591
1592
assoc_segments={:?})",
1592
- def ,
1593
+ base_def ,
1593
1594
base_segments,
1594
1595
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
+
1603
1605
// If any associated type segments remain, attempt to resolve them.
1606
+ let ( mut ty, mut def) = ( base_ty, base_def) ;
1604
1607
for segment in assoc_segments {
1605
1608
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 {
1607
1615
break ;
1608
1616
}
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;
1616
1617
}
1617
1618
( ty, def)
1618
1619
}
@@ -1719,23 +1720,22 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1719
1720
hir:: TyPath ( ref maybe_qself, ref path) => {
1720
1721
debug ! ( "ast_ty_to_ty: maybe_qself={:?} path={:?}" , maybe_qself, path) ;
1721
1722
let path_res = tcx. expect_resolution ( ast_ty. id ) ;
1722
- let def = path_res. base_def ;
1723
1723
let base_ty_end = path. segments . len ( ) - path_res. depth ;
1724
1724
let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| {
1725
1725
self . ast_ty_to_ty ( rscope, & qself. ty )
1726
1726
} ) ;
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) ) ;
1739
1739
}
1740
1740
1741
1741
ty
0 commit comments