@@ -138,23 +138,16 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
138
138
}
139
139
}
140
140
141
- fn bind_params ( fcx : @fn_ctxt , tp : ty:: t , count : uint )
142
- -> { ids : [ int ] , ty: ty:: t } {
143
- ty:: bind_params_in_type ( fcx. ccx . tcx , { || next_ty_var_id ( fcx) } , tp, count)
144
- }
145
-
146
141
// Instantiates the given path, which must refer to an item with the given
147
142
// number of type parameters and type.
148
143
fn instantiate_path ( fcx : @fn_ctxt , pth : @ast:: path ,
149
144
tpt : ty_param_bounds_and_ty , sp : span )
150
145
-> ty_param_substs_opt_and_ty {
151
146
let ty_param_count = vec:: len ( * tpt. bounds ) ;
152
- let bind_result = bind_params ( fcx, tpt. ty , ty_param_count) ;
153
- let ty_param_vars = bind_result. ids ;
154
- let ty_substs_opt;
155
- let ty_substs_len = vec:: len :: < @ast:: ty > ( pth. node . types ) ;
147
+ let vars = vec:: init_fn ( { |_i| next_ty_var ( fcx) } , ty_param_count) ;
148
+ let ty_substs_len = vec:: len ( pth. node . types ) ;
156
149
if ty_substs_len > 0 u {
157
- let param_var_len = vec:: len ( ty_param_vars ) ;
150
+ let param_var_len = vec:: len ( vars ) ;
158
151
if param_var_len == 0 u {
159
152
fcx. ccx . tcx . sess . span_fatal
160
153
( sp, "this item does not take type parameters" ) ;
@@ -165,32 +158,16 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
165
158
fcx. ccx . tcx . sess . span_fatal
166
159
( sp, "not enough type parameters provided for this item" ) ;
167
160
}
168
- let ty_substs: [ ty:: t ] = [ ] ;
169
- let i = 0 u;
170
- while i < ty_substs_len {
171
- let ty_var = ty:: mk_var ( fcx. ccx . tcx , ty_param_vars[ i] ) ;
172
- let ty_subst = ast_ty_to_ty_crate ( fcx. ccx , pth. node . types [ i] ) ;
173
- let res_ty = demand:: simple ( fcx, pth. span , ty_var, ty_subst) ;
174
- ty_substs += [ res_ty] ;
175
- i += 1 u;
161
+ vec:: iter2 ( pth. node . types , vars) { |sub, var|
162
+ let ty_subst = ast_ty_to_ty_crate ( fcx. ccx , sub) ;
163
+ demand:: simple ( fcx, pth. span , var, ty_subst) ;
176
164
}
177
- ty_substs_opt = some :: < [ ty:: t ] > ( ty_substs) ;
178
165
if ty_param_count == 0 u {
179
- fcx. ccx . tcx . sess . span_fatal ( sp,
180
- "this item does not take type \
181
- parameters") ;
182
- }
183
- } else {
184
- // We will acquire the type parameters through unification.
185
- let ty_substs: [ ty:: t ] = [ ] ;
186
- let i = 0 u;
187
- while i < ty_param_count {
188
- ty_substs += [ ty:: mk_var ( fcx. ccx . tcx , ty_param_vars[ i] ) ] ;
189
- i += 1 u;
166
+ fcx. ccx . tcx . sess . span_fatal (
167
+ sp, "this item does not take type parameters" ) ;
190
168
}
191
- ty_substs_opt = some :: < [ ty:: t ] > ( ty_substs) ;
192
169
}
193
- ret { substs : ty_substs_opt , ty : tpt. ty } ;
170
+ { substs : some ( vars ) , ty: tpt. ty }
194
171
}
195
172
196
173
// Type tests
@@ -1555,9 +1532,9 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
1555
1532
alt vec:: find ( methods, { |m| m. ident == name} ) {
1556
1533
some ( m) {
1557
1534
let { n_tps, ty: self_ty } = impl_self_ty ( tcx, did) ;
1558
- let { ids , ty: self_ty } = if n_tps > 0 u {
1535
+ let { vars , ty: self_ty } = if n_tps > 0 u {
1559
1536
bind_params ( fcx, self_ty, n_tps)
1560
- } else { { ids : [ ] , ty: self_ty} } ;
1537
+ } else { { vars : [ ] , ty: self_ty} } ;
1561
1538
alt unify:: unify ( fcx, ty, self_ty) {
1562
1539
ures_ok ( _) {
1563
1540
if option:: is_some ( result) {
@@ -1568,7 +1545,7 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
1568
1545
result = some ( {
1569
1546
method_ty: ty_from_did ( tcx, m. did ) ,
1570
1547
n_tps: m. n_tps ,
1571
- substs: vec :: map ( ids , { |id| ty :: mk_var ( tcx , id ) } ) ,
1548
+ substs: vars ,
1572
1549
origin: method_static ( m. did )
1573
1550
} ) ;
1574
1551
}
@@ -2451,6 +2428,12 @@ fn next_ty_var(fcx: @fn_ctxt) -> ty::t {
2451
2428
ret ty:: mk_var ( fcx. ccx . tcx , next_ty_var_id ( fcx) ) ;
2452
2429
}
2453
2430
2431
+ fn bind_params ( fcx : @fn_ctxt , tp : ty:: t , count : uint )
2432
+ -> { vars : [ ty:: t ] , ty: ty:: t } {
2433
+ let vars = vec:: init_fn ( { |_i| next_ty_var ( fcx) } , count) ;
2434
+ { vars: vars, ty: ty:: substitute_type_params ( fcx. ccx . tcx , vars, tp) }
2435
+ }
2436
+
2454
2437
fn get_self_info ( ccx : @crate_ctxt ) -> option:: t < self_info > {
2455
2438
ret vec:: last ( ccx. self_infos ) ;
2456
2439
}
@@ -2951,10 +2934,9 @@ mod dict {
2951
2934
for im in * impls {
2952
2935
if im. iface_did == some ( iface_id) {
2953
2936
let { n_tps, ty: self_ty } = impl_self_ty ( tcx, im. did ) ;
2954
- let { ids , ty: self_ty } = if n_tps > 0 u {
2937
+ let { vars , ty: self_ty } = if n_tps > 0 u {
2955
2938
bind_params ( fcx, self_ty, n_tps)
2956
- } else { { ids: [ ] , ty: self_ty} } ;
2957
- let vars = vec:: map ( ids, { |id| ty:: mk_var ( tcx, id) } ) ;
2939
+ } else { { vars: [ ] , ty: self_ty} } ;
2958
2940
let im_bs = ty:: lookup_item_type ( tcx, im. did ) . bounds ;
2959
2941
// FIXME[impl] don't do this in fcx (or make
2960
2942
// unify transactional by scrubbing bindings on fail)
0 commit comments