@@ -89,42 +89,55 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
8989 where FR : FnMut ( & ty:: RegionParameterDef , & Substs < ' tcx > ) -> ty:: Region ,
9090 FT : FnMut ( & ty:: TypeParameterDef < ' tcx > , & Substs < ' tcx > ) -> Ty < ' tcx > {
9191 let defs = tcx. lookup_generics ( def_id) ;
92+ let num_regions = defs. parent_regions as usize + defs. regions . len ( ) ;
93+ let num_types = defs. parent_types as usize + defs. types . len ( ) ;
9294 let mut substs = Substs {
93- types : VecPerParamSpace {
95+ regions : VecPerParamSpace {
9496 type_limit : 0 ,
95- content : Vec :: with_capacity ( defs . types . content . len ( ) )
97+ content : Vec :: with_capacity ( num_regions )
9698 } ,
97- regions : VecPerParamSpace {
99+ types : VecPerParamSpace {
98100 type_limit : 0 ,
99- content : Vec :: with_capacity ( defs . regions . content . len ( ) )
101+ content : Vec :: with_capacity ( num_types )
100102 }
101103 } ;
102104
103- for & space in & ParamSpace :: all ( ) {
104- for def in defs. regions . get_slice ( space) {
105- assert_eq ! ( def. space, space) ;
106-
107- let region = mk_region ( def, & substs) ;
108- substs. regions . content . push ( region) ;
105+ substs. fill_item ( tcx, defs, & mut mk_region, & mut mk_type) ;
109106
110- if space == TypeSpace {
111- substs. regions . type_limit += 1 ;
112- }
113- }
107+ Substs :: new ( tcx, substs. types , substs. regions )
108+ }
114109
115- for def in defs. types . get_slice ( space) {
116- assert_eq ! ( def. space, space) ;
110+ fn fill_item < FR , FT > ( & mut self ,
111+ tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
112+ defs : & ty:: Generics < ' tcx > ,
113+ mk_region : & mut FR ,
114+ mk_type : & mut FT )
115+ where FR : FnMut ( & ty:: RegionParameterDef , & Substs < ' tcx > ) -> ty:: Region ,
116+ FT : FnMut ( & ty:: TypeParameterDef < ' tcx > , & Substs < ' tcx > ) -> Ty < ' tcx > {
117+ if let Some ( def_id) = defs. parent {
118+ let parent_defs = tcx. lookup_generics ( def_id) ;
119+ self . fill_item ( tcx, parent_defs, mk_region, mk_type) ;
120+ }
117121
118- let ty = mk_type ( def, & substs) ;
119- substs. types . content . push ( ty) ;
122+ for def in & defs. regions {
123+ let region = mk_region ( def, self ) ;
124+ self . regions . content . push ( region) ;
120125
121- if space == TypeSpace {
122- substs . types . type_limit += 1 ;
123- }
126+ if def . space == TypeSpace {
127+ self . regions . type_limit += 1 ;
128+ assert_eq ! ( self . regions . content . len ( ) , self . regions . type_limit ) ;
124129 }
125130 }
126131
127- Substs :: new ( tcx, substs. types , substs. regions )
132+ for def in & defs. types {
133+ let ty = mk_type ( def, self ) ;
134+ self . types . content . push ( ty) ;
135+
136+ if def. space == TypeSpace {
137+ self . types . type_limit += 1 ;
138+ assert_eq ! ( self . types. content. len( ) , self . types. type_limit) ;
139+ }
140+ }
128141 }
129142
130143 pub fn is_noop ( & self ) -> bool {
@@ -149,16 +162,14 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
149162 target_substs : & Substs < ' tcx > )
150163 -> & ' tcx Substs < ' tcx > {
151164 let defs = tcx. lookup_generics ( source_ancestor) ;
152- assert_eq ! ( self . types. len( TypeSpace ) , defs. types. len( TypeSpace ) ) ;
165+ assert_eq ! ( self . types. len( TypeSpace ) , defs. types. len( ) ) ;
153166 assert_eq ! ( target_substs. types. len( FnSpace ) , 0 ) ;
154- assert_eq ! ( defs. types. len( FnSpace ) , 0 ) ;
155- assert_eq ! ( self . regions. len( TypeSpace ) , defs. regions. len( TypeSpace ) ) ;
167+ assert_eq ! ( self . regions. len( TypeSpace ) , defs. regions. len( ) ) ;
156168 assert_eq ! ( target_substs. regions. len( FnSpace ) , 0 ) ;
157- assert_eq ! ( defs. regions. len( FnSpace ) , 0 ) ;
158169
159170 let Substs { mut types, mut regions } = target_substs. clone ( ) ;
160- types. content . extend ( & self . types . as_full_slice ( ) [ defs. types . content . len ( ) ..] ) ;
161- regions. content . extend ( & self . regions . as_full_slice ( ) [ defs. regions . content . len ( ) ..] ) ;
171+ types. content . extend ( & self . types . as_full_slice ( ) [ defs. types . len ( ) ..] ) ;
172+ regions. content . extend ( & self . regions . as_full_slice ( ) [ defs. regions . len ( ) ..] ) ;
162173 Substs :: new ( tcx, types, regions)
163174 }
164175}
@@ -597,8 +608,8 @@ impl<'a, 'gcx, 'tcx> ty::TraitRef<'tcx> {
597608 -> ty:: TraitRef < ' tcx > {
598609 let Substs { mut types, mut regions } = substs. clone ( ) ;
599610 let defs = tcx. lookup_generics ( trait_id) ;
600- types. content . truncate ( defs. types . type_limit ) ;
601- regions. content . truncate ( defs. regions . type_limit ) ;
611+ types. content . truncate ( defs. types . len ( ) ) ;
612+ regions. content . truncate ( defs. regions . len ( ) ) ;
602613
603614 ty:: TraitRef {
604615 def_id : trait_id,
0 commit comments