@@ -18,7 +18,7 @@ use hir::def::Def;
1818use hir:: def_id:: DefId ;
1919use middle:: resolve_lifetime as rl;
2020use namespace:: Namespace ;
21- use rustc:: ty:: subst:: { UnpackedKind , Subst , Substs } ;
21+ use rustc:: ty:: subst:: { Subst , Substs } ;
2222use rustc:: traits;
2323use rustc:: ty:: { self , Ty , TyCtxt , ToPredicate , TypeFoldable } ;
2424use rustc:: ty:: GenericParamDefKind ;
@@ -1152,32 +1152,29 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11521152 let tcx = self . tcx ( ) ;
11531153 let generics = tcx. generics_of ( def_id) ;
11541154
1155- // Fill in the substs of the parent generics
11561155 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)
11681172 }
11691173 }
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+ } ) ;
11781175 debug ! ( "impl_trait_ty_to_ty: final substs = {:?}" , substs) ;
11791176
1180- tcx. mk_anon ( def_id, tcx . intern_substs ( & substs) )
1177+ tcx. mk_anon ( def_id, substs)
11811178 }
11821179
11831180 pub fn ty_of_arg ( & self ,
0 commit comments