@@ -381,10 +381,30 @@ fn trans_expr_fn(bcx: block,
381
381
proto : ast:: Proto ,
382
382
+decl : ast:: fn_decl ,
383
383
+body : ast:: blk ,
384
- id : ast:: node_id ,
384
+ outer_id : ast:: node_id ,
385
+ user_id : ast:: node_id ,
385
386
cap_clause : ast:: capture_clause ,
386
387
is_loop_body : Option < Option < ValueRef > > ,
387
- dest : expr:: Dest ) -> block {
388
+ dest : expr:: Dest ) -> block
389
+ {
390
+ /*!
391
+ *
392
+ * Translates the body of a closure expression.
393
+ *
394
+ * - `proto`
395
+ * - `decl`
396
+ * - `body`
397
+ * - `outer_id`: The id of the closure expression with the correct type.
398
+ * This is usually the same as as `user_id`, but in the case of a `for` loop,
399
+ * the `outer_id` will have the return type of boolean, and the `user_id` will
400
+ * have the return type of `nil`.
401
+ * - `user_id`: The id of the closure as the user expressed it. Generally
402
+ the same as `outer_id`
403
+ * - `cap_clause`: information about captured variables, if any.
404
+ * - `is_loop_body`: `Some()` if this is part of a `for` loop.
405
+ * - `dest`: where to write the closure value, which must be a (fn ptr, env) pair
406
+ */
407
+
388
408
let _icx = bcx. insn_ctxt ( "closure::trans_expr_fn" ) ;
389
409
390
410
let dest_addr = match dest {
@@ -395,7 +415,7 @@ fn trans_expr_fn(bcx: block,
395
415
} ;
396
416
397
417
let ccx = bcx. ccx ( ) ;
398
- let fty = node_id_type ( bcx, id ) ;
418
+ let fty = node_id_type ( bcx, outer_id ) ;
399
419
let llfnty = type_of_fn_from_ty ( ccx, fty) ;
400
420
let sub_path = vec:: append_one ( /*bad*/ copy bcx. fcx . path ,
401
421
path_name ( special_idents:: anon) ) ;
@@ -407,14 +427,15 @@ fn trans_expr_fn(bcx: block,
407
427
408
428
// XXX: Bad copies.
409
429
let trans_closure_env = |proto, copy body, copy sub_path, copy decl| {
410
- let cap_vars = capture:: compute_capture_vars ( ccx. tcx , id , proto,
430
+ let cap_vars = capture:: compute_capture_vars ( ccx. tcx , user_id , proto,
411
431
cap_clause) ;
412
432
let ret_handle = match is_loop_body { Some ( x) => x, None => None } ;
413
433
// XXX: Bad copy.
414
434
let { llbox, cdata_ty, bcx} = build_closure ( bcx, copy cap_vars, proto,
415
435
ret_handle) ;
416
436
trans_closure ( ccx, /*bad*/ copy sub_path, decl, body, llfn, no_self,
417
- /*bad*/ copy bcx. fcx . param_substs , id, None , |fcx| {
437
+ /*bad*/ copy bcx. fcx . param_substs , user_id, None ,
438
+ |fcx| {
418
439
load_environment ( fcx, cdata_ty, copy cap_vars,
419
440
ret_handle. is_some ( ) , proto) ;
420
441
} , |bcx| {
@@ -431,7 +452,7 @@ fn trans_expr_fn(bcx: block,
431
452
}
432
453
ast:: ProtoBare => {
433
454
trans_closure ( ccx, sub_path, decl, body, llfn, no_self, None ,
434
- id , None , |_fcx| { } , |_bcx| { } ) ;
455
+ user_id , None , |_fcx| { } , |_bcx| { } ) ;
435
456
rslt ( bcx, C_null ( T_opaque_box_ptr ( ccx) ) )
436
457
}
437
458
} ;
0 commit comments