@@ -18,7 +18,7 @@ use hir::def::Def;
18
18
use hir:: def_id:: DefId ;
19
19
use middle:: resolve_lifetime as rl;
20
20
use namespace:: Namespace ;
21
- use rustc:: ty:: subst:: { UnpackedKind , Subst , Substs } ;
21
+ use rustc:: ty:: subst:: { Subst , Substs } ;
22
22
use rustc:: traits;
23
23
use rustc:: ty:: { self , Ty , TyCtxt , ToPredicate , TypeFoldable } ;
24
24
use rustc:: ty:: GenericParamDefKind ;
@@ -1152,32 +1152,29 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1152
1152
let tcx = self . tcx ( ) ;
1153
1153
let generics = tcx. generics_of ( def_id) ;
1154
1154
1155
- // Fill in the substs of the parent generics
1156
1155
debug ! ( "impl_trait_ty_to_ty: generics={:?}" , generics) ;
1157
- let mut substs = Vec :: with_capacity ( generics. count ( ) ) ;
1158
- if let Some ( parent_id) = generics. parent {
1159
- let parent_generics = tcx. generics_of ( parent_id) ;
1160
- Substs :: fill_item ( & mut substs, tcx, parent_generics, & mut |param, _| {
1161
- tcx. mk_param_from_def ( param)
1162
- } ) ;
1163
-
1164
- // Replace all lifetimes with 'static
1165
- for subst in & mut substs {
1166
- if let UnpackedKind :: Lifetime ( _) = subst. unpack ( ) {
1167
- * subst = tcx. types . re_static . into ( ) ;
1156
+ let substs = Substs :: for_item ( tcx, def_id, |param, _| {
1157
+ if let Some ( i) = ( param. index as usize ) . checked_sub ( generics. parent_count ) {
1158
+ // Our own parameters are the resolved lifetimes.
1159
+ match param. kind {
1160
+ GenericParamDefKind :: Lifetime => {
1161
+ self . ast_region_to_region ( & lifetimes[ i] , None ) . into ( )
1162
+ }
1163
+ _ => bug ! ( )
1164
+ }
1165
+ } else {
1166
+ // Replace all parent lifetimes with 'static.
1167
+ match param. kind {
1168
+ GenericParamDefKind :: Lifetime => {
1169
+ tcx. types . re_static . into ( )
1170
+ }
1171
+ _ => tcx. mk_param_from_def ( param)
1168
1172
}
1169
1173
}
1170
- debug ! ( "impl_trait_ty_to_ty: substs from parent = {:?}" , substs) ;
1171
- }
1172
- assert_eq ! ( substs. len( ) , generics. parent_count) ;
1173
-
1174
- // Fill in our own generics with the resolved lifetimes
1175
- assert_eq ! ( lifetimes. len( ) , generics. params. len( ) ) ;
1176
- substs. extend ( lifetimes. iter ( ) . map ( |lt| self . ast_region_to_region ( lt, None ) . into ( ) ) ) ;
1177
-
1174
+ } ) ;
1178
1175
debug ! ( "impl_trait_ty_to_ty: final substs = {:?}" , substs) ;
1179
1176
1180
- tcx. mk_anon ( def_id, tcx . intern_substs ( & substs) )
1177
+ tcx. mk_anon ( def_id, substs)
1181
1178
}
1182
1179
1183
1180
pub fn ty_of_arg ( & self ,
0 commit comments