@@ -1201,45 +1201,39 @@ type gather_result =
1201
1201
// Used only as a helper for check_fn.
1202
1202
fn gather_locals ( ccx : & @crate_ctxt , f : & ast:: _fn , id : & ast:: node_id ,
1203
1203
old_fcx : & option:: t[ @fn_ctxt ] ) -> gather_result {
1204
- fn next_var_id ( nvi : @mutable int ) -> int {
1204
+ let { vb, locals, local_names, nvi} = alt old_fcx {
1205
+ none. {
1206
+ { vb : ty:: unify:: mk_var_bindings ( ) ,
1207
+ locals : new_int_hash[ int] ( ) ,
1208
+ local_names : new_int_hash[ ast:: ident] ( ) ,
1209
+ nvi : @mutable 0 }
1210
+ }
1211
+ some ( fcx) {
1212
+ { vb: fcx. var_bindings ,
1213
+ locals: fcx. locals ,
1214
+ local_names: fcx. local_names ,
1215
+ nvi: fcx. next_var_id }
1216
+ }
1217
+ } ;
1218
+ let tcx = ccx. tcx ;
1219
+
1220
+ let next_var_id = lambda ( nvi: @mutable int) -> int {
1205
1221
let rv = * nvi;
1206
1222
* nvi += 1 ;
1207
1223
ret rv;
1208
- }
1209
- fn assign ( tcx : & ty:: ctxt , var_bindings : & @ty:: unify:: var_bindings ,
1210
- locals : & hashmap[ ast:: node_id , int ] ,
1211
- local_names : & hashmap[ ast:: node_id , ast:: ident ] ,
1212
- nvi : @mutable int , nid : ast:: node_id , ident : & ast:: ident ,
1213
- ty_opt : option:: t [ ty:: t ] ) {
1224
+ } ;
1225
+ let assign = lambda ( nid: ast:: node_id, ident: & ast:: ident,
1226
+ ty_opt: option:: t[ ty:: t] ) {
1214
1227
let var_id = next_var_id ( nvi) ;
1215
1228
locals. insert ( nid, var_id) ;
1216
1229
local_names. insert ( nid, ident) ;
1217
1230
alt ty_opt {
1218
- none[ ty :: t ] . { /* nothing to do */ }
1219
- some[ ty :: t ] ( typ) {
1220
- ty:: unify:: unify ( ty:: mk_var ( tcx, var_id) , typ, var_bindings , tcx) ;
1231
+ none. { /* nothing to do */ }
1232
+ some( typ) {
1233
+ ty:: unify:: unify ( ty:: mk_var ( tcx, var_id) , typ, vb , tcx) ;
1221
1234
}
1222
1235
}
1223
- }
1224
-
1225
- let vb;
1226
- let locals;
1227
- let local_names;
1228
- let nvi;
1229
- alt old_fcx {
1230
- none. {
1231
- vb = ty:: unify:: mk_var_bindings ( ) ;
1232
- locals = new_int_hash[ int] ( ) ;
1233
- local_names = new_int_hash[ ast:: ident] ( ) ;
1234
- nvi = @mutable 0 ;
1235
- }
1236
- some ( fcx) {
1237
- vb = fcx. var_bindings ;
1238
- locals = fcx. locals ;
1239
- local_names = fcx. local_names ;
1240
- nvi = fcx. next_var_id ;
1241
- }
1242
- }
1236
+ } ;
1243
1237
1244
1238
// Add object fields, if any.
1245
1239
let obj_fields = ~[ ] ;
@@ -1254,68 +1248,53 @@ fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id,
1254
1248
}
1255
1249
for f: ast:: obj_field in obj_fields {
1256
1250
let field_ty = ty:: node_id_to_type ( ccx. tcx , f. id ) ;
1257
- assign ( ccx. tcx , vb, locals, local_names, nvi, f. id , f. ident ,
1258
- some ( field_ty) ) ;
1251
+ assign ( f. id , f. ident , some ( field_ty) ) ;
1259
1252
}
1260
1253
1261
1254
// Add formal parameters.
1262
1255
let args = ty:: ty_fn_args ( ccx. tcx , ty:: node_id_to_type ( ccx. tcx , id) ) ;
1263
1256
let i = 0 u;
1264
1257
for arg: ty:: arg in args {
1265
- assign ( ccx. tcx , vb, locals, local_names, nvi, f. decl . inputs . ( i) . id ,
1266
- f. decl . inputs . ( i) . ident , some[ ty:: t] ( arg. ty ) ) ;
1258
+ assign ( f. decl . inputs . ( i) . id , f. decl . inputs . ( i) . ident , some ( arg. ty ) ) ;
1267
1259
i += 1 u;
1268
1260
}
1269
1261
1270
1262
// Add explicitly-declared locals.
1271
- fn visit_local ( ccx : @crate_ctxt , vb : @ty:: unify:: var_bindings ,
1272
- locals : hashmap[ ast:: node_id , int ] ,
1273
- local_names : hashmap[ ast:: node_id , ast:: ident ] ,
1274
- nvi : @mutable int , local : & @ast:: local , e : & ( ) ,
1275
- v : & visit:: vt [ ( ) ] ) {
1263
+ let visit_local = lambda ( local: & @ast:: local, e: & ( ) , v: & visit:: vt[ ( ) ] ) {
1276
1264
alt local. node . ty {
1277
1265
none. {
1278
1266
// Auto slot.
1279
- assign ( ccx. tcx , vb, locals, local_names, nvi, local. node . id ,
1280
- ident_for_local ( local) , none) ;
1267
+ assign ( local. node . id , ident_for_local ( local) , none) ;
1281
1268
}
1282
1269
some ( ast_ty) {
1283
1270
// Explicitly typed slot.
1284
1271
let local_ty = ast_ty_to_ty_crate ( ccx, ast_ty) ;
1285
- assign ( ccx. tcx , vb, locals, local_names, nvi, local. node . id ,
1286
- ident_for_local ( local) , some ( local_ty) ) ;
1272
+ assign ( local. node . id , ident_for_local ( local) , some ( local_ty) ) ;
1287
1273
}
1288
1274
}
1289
1275
visit:: visit_local ( local, e, v) ;
1290
- }
1276
+ } ;
1291
1277
1292
1278
// Add pattern bindings.
1293
- fn visit_pat ( ccx : @crate_ctxt , vb : @ty:: unify:: var_bindings ,
1294
- locals : hashmap[ ast:: node_id , int ] ,
1295
- local_names : hashmap[ ast:: node_id , ast:: ident ] ,
1296
- nvi : @mutable int , p : & @ast:: pat , e : & ( ) ,
1297
- v : & visit:: vt [ ( ) ] ) {
1279
+ let visit_pat = lambda ( p: & @ast:: pat, e: & ( ) , v: & visit:: vt[ ( ) ] ) {
1298
1280
alt p. node {
1299
1281
ast:: pat_bind ( ident) {
1300
- assign ( ccx . tcx , vb , locals , local_names , nvi , p. id , ident, none) ;
1282
+ assign ( p. id , ident, none) ;
1301
1283
}
1302
1284
_ { /* no-op */ }
1303
1285
}
1304
1286
visit:: visit_pat ( p, e, v) ;
1305
- }
1287
+ } ;
1306
1288
1307
1289
// Don't descend into fns and items
1308
1290
fn visit_fn[ E ] ( f: & ast:: _fn, tp: & ast:: ty_param[ ] , sp: & span,
1309
1291
i: & ast:: fn_ident, id: ast:: node_id, e: & E ,
1310
- v: & visit:: vt[ E ] ) {
1311
- }
1292
+ v: & visit:: vt[ E ] ) { }
1312
1293
fn visit_item[ E ] ( i: & @ast:: item, e: & E , v: & visit:: vt[ E ] ) { }
1313
1294
1314
1295
let visit =
1315
- @{ visit_local:
1316
- bind visit_local ( ccx, vb, locals, local_names, nvi, _, _, _) ,
1317
- visit_pat:
1318
- bind visit_pat ( ccx, vb, locals, local_names, nvi, _, _, _) ,
1296
+ @{ visit_local: visit_local,
1297
+ visit_pat: visit_pat,
1319
1298
visit_fn: visit_fn,
1320
1299
visit_item: visit_item with * visit:: default_visitor ( ) } ;
1321
1300
visit:: visit_block ( f. body , ( ) , visit:: mk_vt ( visit) ) ;
0 commit comments