Skip to content

Commit 3e2929d

Browse files
committed
Merge the ExprFnBlock and ExprUnboxedClosure into one ExprClosure with an optional unboxed closure kind.
1 parent 8e44688 commit 3e2929d

27 files changed

+126
-187
lines changed

src/librustc/middle/borrowck/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,12 @@ pub fn closure_to_block(closure_id: ast::NodeId,
288288
match tcx.map.get(closure_id) {
289289
ast_map::NodeExpr(expr) => match expr.node {
290290
ast::ExprProc(_, ref block) |
291-
ast::ExprFnBlock(_, _, ref block) |
292-
ast::ExprUnboxedFn(_, _, _, ref block) => { block.id }
293-
_ => panic!("encountered non-closure id: {}", closure_id)
291+
ast::ExprClosure(_, _, _, ref block) => {
292+
block.id
293+
}
294+
_ => {
295+
panic!("encountered non-closure id: {}", closure_id)
296+
}
294297
},
295298
_ => panic!("encountered non-expr id: {}", closure_id)
296299
}

src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
496496
}
497497

498498
ast::ExprMac(..) |
499-
ast::ExprFnBlock(..) |
499+
ast::ExprClosure(..) |
500500
ast::ExprProc(..) |
501-
ast::ExprUnboxedFn(..) |
502501
ast::ExprLit(..) |
503502
ast::ExprPath(..) => {
504503
self.straightline(expr, pred, None::<ast::Expr>.iter())

src/librustc/middle/check_loop.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
4848
self.visit_expr(&**e);
4949
self.with_context(Loop, |v| v.visit_block(&**b));
5050
}
51-
ast::ExprFnBlock(_, _, ref b) |
52-
ast::ExprProc(_, ref b) |
53-
ast::ExprUnboxedFn(_, _, _, ref b) => {
51+
ast::ExprClosure(_, _, _, ref b) |
52+
ast::ExprProc(_, ref b) => {
5453
self.with_context(Closure, |v| v.visit_block(&**b));
5554
}
5655
ast::ExprBreak(_) => self.require_loop("break", e.span),

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
496496
self.consume_expr(&**count);
497497
}
498498

499-
ast::ExprFnBlock(..) |
500-
ast::ExprUnboxedFn(..) |
499+
ast::ExprClosure(..) |
501500
ast::ExprProc(..) => {
502501
self.walk_captures(expr)
503502
}

src/librustc/middle/liveness.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
458458
}
459459
visit::walk_expr(ir, expr);
460460
}
461-
ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprUnboxedFn(..) => {
461+
ast::ExprClosure(..) | ast::ExprProc(..) => {
462462
// Interesting control flow (for loops can contain labeled
463463
// breaks or continues)
464464
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
@@ -975,10 +975,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
975975
self.propagate_through_expr(&**e, succ)
976976
}
977977

978-
ast::ExprFnBlock(_, _, ref blk) |
979-
ast::ExprProc(_, ref blk) |
980-
ast::ExprUnboxedFn(_, _, _, ref blk) => {
981-
debug!("{} is an ExprFnBlock, ExprProc, or ExprUnboxedFn",
978+
ast::ExprClosure(_, _, _, ref blk) |
979+
ast::ExprProc(_, ref blk) => {
980+
debug!("{} is an ExprClosure or ExprProc",
982981
expr_to_string(expr));
983982

984983
/*
@@ -1495,7 +1494,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14951494
ast::ExprBreak(..) | ast::ExprAgain(..) | ast::ExprLit(_) |
14961495
ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) |
14971496
ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) |
1498-
ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprUnboxedFn(..) |
1497+
ast::ExprClosure(..) | ast::ExprProc(..) |
14991498
ast::ExprPath(..) | ast::ExprBox(..) | ast::ExprSlice(..) => {
15001499
visit::walk_expr(this, expr);
15011500
}

src/librustc/middle/mem_categorization.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
520520

521521
ast::ExprAddrOf(..) | ast::ExprCall(..) |
522522
ast::ExprAssign(..) | ast::ExprAssignOp(..) |
523-
ast::ExprFnBlock(..) | ast::ExprProc(..) |
524-
ast::ExprUnboxedFn(..) | ast::ExprRet(..) |
523+
ast::ExprClosure(..) | ast::ExprProc(..) |
524+
ast::ExprRet(..) |
525525
ast::ExprUnary(..) | ast::ExprSlice(..) |
526526
ast::ExprMethodCall(..) | ast::ExprCast(..) |
527527
ast::ExprVec(..) | ast::ExprTup(..) | ast::ExprIf(..) |
@@ -693,9 +693,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
693693
};
694694

695695
match fn_expr.node {
696-
ast::ExprFnBlock(_, _, ref body) |
697696
ast::ExprProc(_, ref body) |
698-
ast::ExprUnboxedFn(_, _, _, ref body) => body.id,
697+
ast::ExprClosure(_, _, _, ref body) => body.id,
699698
_ => unreachable!()
700699
}
701700
};

src/librustc/middle/resolve.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ use util::nodemap::{NodeMap, NodeSet, DefIdSet, FnvHashMap};
5050

5151
use syntax::ast::{Arm, BindByRef, BindByValue, BindingMode, Block, Crate, CrateNum};
5252
use syntax::ast::{DeclItem, DefId, Expr, ExprAgain, ExprBreak, ExprField};
53-
use syntax::ast::{ExprFnBlock, ExprForLoop, ExprLoop, ExprWhile, ExprMethodCall};
54-
use syntax::ast::{ExprPath, ExprProc, ExprStruct, ExprUnboxedFn, FnDecl};
53+
use syntax::ast::{ExprClosure, ExprForLoop, ExprLoop, ExprWhile, ExprMethodCall};
54+
use syntax::ast::{ExprPath, ExprProc, ExprStruct, FnDecl};
5555
use syntax::ast::{ForeignItem, ForeignItemFn, ForeignItemStatic, Generics};
5656
use syntax::ast::{Ident, ImplItem, Item, ItemEnum, ItemFn, ItemForeignMod};
5757
use syntax::ast::{ItemImpl, ItemMac, ItemMod, ItemStatic, ItemStruct};
@@ -5903,24 +5903,19 @@ impl<'a> Resolver<'a> {
59035903
visit::walk_expr(self, expr);
59045904
}
59055905

5906-
ExprFnBlock(capture_clause, ref fn_decl, ref block) => {
5906+
ExprClosure(capture_clause, _, ref fn_decl, ref block) => {
59075907
self.capture_mode_map.insert(expr.id, capture_clause);
59085908
self.resolve_function(ClosureRibKind(expr.id, ast::DUMMY_NODE_ID),
59095909
Some(&**fn_decl), NoTypeParameters,
59105910
&**block);
59115911
}
5912+
59125913
ExprProc(ref fn_decl, ref block) => {
59135914
self.capture_mode_map.insert(expr.id, ast::CaptureByValue);
59145915
self.resolve_function(ClosureRibKind(expr.id, block.id),
59155916
Some(&**fn_decl), NoTypeParameters,
59165917
&**block);
59175918
}
5918-
ExprUnboxedFn(capture_clause, _, ref fn_decl, ref block) => {
5919-
self.capture_mode_map.insert(expr.id, capture_clause);
5920-
self.resolve_function(ClosureRibKind(expr.id, block.id),
5921-
Some(&**fn_decl), NoTypeParameters,
5922-
&**block);
5923-
}
59245919

59255920
ExprStruct(ref path, _, _) => {
59265921
// Resolve the path to the structure it goes to. We don't

src/librustc/middle/ty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3922,9 +3922,8 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
39223922
ast::ExprTup(..) |
39233923
ast::ExprIf(..) |
39243924
ast::ExprMatch(..) |
3925-
ast::ExprFnBlock(..) |
3925+
ast::ExprClosure(..) |
39263926
ast::ExprProc(..) |
3927-
ast::ExprUnboxedFn(..) |
39283927
ast::ExprBlock(..) |
39293928
ast::ExprRepeat(..) |
39303929
ast::ExprVec(..) => {

src/librustc/middle/typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
10471047
}
10481048
ast::TyInfer => {
10491049
// TyInfer also appears as the type of arguments or return
1050-
// values in a ExprFnBlock, ExprProc, or ExprUnboxedFn, or as
1050+
// values in a ExprClosure or ExprProc, or as
10511051
// the type of local variables. Both of these cases are
10521052
// handled specially and will not descend into this routine.
10531053
this.ty_infer(ast_ty.span)

src/librustc/middle/typeck/check/closure.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,38 @@ use syntax::ast;
2626
use syntax::ast_util;
2727
use util::ppaux::Repr;
2828

29-
pub fn check_unboxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
30-
expr: &ast::Expr,
31-
kind: ast::UnboxedClosureKind,
32-
decl: &ast::FnDecl,
33-
body: &ast::Block,
34-
expected: Expectation<'tcx>) {
29+
pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
30+
expr: &ast::Expr,
31+
opt_kind: Option<ast::UnboxedClosureKind>,
32+
decl: &ast::FnDecl,
33+
body: &ast::Block,
34+
expected: Expectation<'tcx>) {
35+
match opt_kind {
36+
None => { // old-school boxed closure
37+
let region = astconv::opt_ast_region_to_region(fcx,
38+
fcx.infcx(),
39+
expr.span,
40+
&None);
41+
check_boxed_closure(fcx,
42+
expr,
43+
ty::RegionTraitStore(region, ast::MutMutable),
44+
decl,
45+
body,
46+
expected);
47+
}
48+
49+
Some(kind) => {
50+
check_unboxed_closure(fcx, expr, kind, decl, body, expected)
51+
}
52+
}
53+
}
54+
55+
fn check_unboxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
56+
expr: &ast::Expr,
57+
kind: ast::UnboxedClosureKind,
58+
decl: &ast::FnDecl,
59+
body: &ast::Block,
60+
expected: Expectation<'tcx>) {
3561
let expr_def_id = ast_util::local_def(expr.id);
3662

3763
let expected_sig_and_kind = match expected.resolve(fcx) {
@@ -215,12 +241,12 @@ fn deduce_unboxed_closure_expectations_from_obligations<'a,'tcx>(
215241
}
216242

217243

218-
pub fn check_expr_fn<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
219-
expr: &ast::Expr,
220-
store: ty::TraitStore,
221-
decl: &ast::FnDecl,
222-
body: &ast::Block,
223-
expected: Expectation<'tcx>) {
244+
pub fn check_boxed_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
245+
expr: &ast::Expr,
246+
store: ty::TraitStore,
247+
decl: &ast::FnDecl,
248+
body: &ast::Block,
249+
expected: Expectation<'tcx>) {
224250
let tcx = fcx.ccx.tcx;
225251

226252
// Find the expected input/output types (if any). Substitute

src/librustc/middle/typeck/check/mod.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,9 +2823,7 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
28232823
};
28242824
for (i, arg) in args.iter().take(t).enumerate() {
28252825
let is_block = match arg.node {
2826-
ast::ExprFnBlock(..) |
2827-
ast::ExprProc(..) |
2828-
ast::ExprUnboxedFn(..) => true,
2826+
ast::ExprClosure(..) | ast::ExprProc(..) => true,
28292827
_ => false
28302828
};
28312829

@@ -4148,33 +4146,16 @@ fn check_expr_with_unifier<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
41484146
ast::ExprMatch(ref discrim, ref arms, _) => {
41494147
_match::check_match(fcx, expr, &**discrim, arms.as_slice());
41504148
}
4151-
ast::ExprFnBlock(_, ref decl, ref body) => {
4152-
let region = astconv::opt_ast_region_to_region(fcx,
4153-
fcx.infcx(),
4154-
expr.span,
4155-
&None);
4156-
closure::check_expr_fn(fcx,
4157-
expr,
4158-
ty::RegionTraitStore(region, ast::MutMutable),
4159-
&**decl,
4160-
&**body,
4161-
expected);
4162-
}
4163-
ast::ExprUnboxedFn(_, kind, ref decl, ref body) => {
4164-
closure::check_unboxed_closure(fcx,
4165-
expr,
4166-
kind,
4167-
&**decl,
4168-
&**body,
4169-
expected);
4149+
ast::ExprClosure(_, opt_kind, ref decl, ref body) => {
4150+
closure::check_expr_closure(fcx, expr, opt_kind, &**decl, &**body, expected);
41704151
}
41714152
ast::ExprProc(ref decl, ref body) => {
4172-
closure::check_expr_fn(fcx,
4173-
expr,
4174-
ty::UniqTraitStore,
4175-
&**decl,
4176-
&**body,
4177-
expected);
4153+
closure::check_boxed_closure(fcx,
4154+
expr,
4155+
ty::UniqTraitStore,
4156+
&**decl,
4157+
&**body,
4158+
expected);
41784159
}
41794160
ast::ExprBlock(ref b) => {
41804161
check_block_with_expected(fcx, &**b, expected);

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,8 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
742742
visit::walk_expr(rcx, expr);
743743
}
744744

745-
ast::ExprFnBlock(_, _, ref body) |
746745
ast::ExprProc(_, ref body) |
747-
ast::ExprUnboxedFn(_, _, _, ref body) => {
746+
ast::ExprClosure(_, _, _, ref body) => {
748747
check_expr_fn_block(rcx, expr, &**body);
749748
}
750749

src/librustc/middle/typeck/check/writeback.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
122122
MethodCall::expr(e.id));
123123

124124
match e.node {
125-
ast::ExprFnBlock(_, ref decl, _) |
126-
ast::ExprProc(ref decl, _) |
127-
ast::ExprUnboxedFn(_, _, ref decl, _) => {
125+
ast::ExprClosure(_, _, ref decl, _) |
126+
ast::ExprProc(ref decl, _) => {
128127
for input in decl.inputs.iter() {
129128
let _ = self.visit_node_id(ResolvingExpr(e.span),
130129
input.id);

src/librustc_back/svh.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ mod svh_visitor {
241241
SawExprIf,
242242
SawExprWhile,
243243
SawExprMatch,
244-
SawExprFnBlock,
245-
SawExprUnboxedFn,
244+
SawExprClosure,
246245
SawExprProc,
247246
SawExprBlock,
248247
SawExprAssign,
@@ -274,8 +273,7 @@ mod svh_visitor {
274273
ExprWhile(..) => SawExprWhile,
275274
ExprLoop(_, id) => SawExprLoop(id.map(content)),
276275
ExprMatch(..) => SawExprMatch,
277-
ExprFnBlock(..) => SawExprFnBlock,
278-
ExprUnboxedFn(..) => SawExprUnboxedFn,
276+
ExprClosure(..) => SawExprClosure,
279277
ExprProc(..) => SawExprProc,
280278
ExprBlock(..) => SawExprBlock,
281279
ExprAssign(..) => SawExprAssign,

src/librustc_trans/save/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
13451345
"Expected struct type, but not ty_struct"),
13461346
}
13471347
},
1348-
ast::ExprFnBlock(_, ref decl, ref body) => {
1348+
ast::ExprClosure(_, _, ref decl, ref body) => {
13491349
if generated_code(body.span) {
13501350
return
13511351
}

src/librustc_trans/trans/base.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,9 +1385,8 @@ fn has_nested_returns(tcx: &ty::ctxt, id: ast::NodeId) -> bool {
13851385
}
13861386
Some(ast_map::NodeExpr(e)) => {
13871387
match e.node {
1388-
ast::ExprFnBlock(_, _, ref blk) |
1389-
ast::ExprProc(_, ref blk) |
1390-
ast::ExprUnboxedFn(_, _, _, ref blk) => {
1388+
ast::ExprClosure(_, _, _, ref blk) |
1389+
ast::ExprProc(_, ref blk) => {
13911390
let mut explicit = CheckForNestedReturnsVisitor::explicit();
13921391
let mut implicit = CheckForNestedReturnsVisitor::implicit();
13931392
visit::walk_expr(&mut explicit, e);

src/librustc_trans/trans/debuginfo.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,8 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
12321232
}
12331233
ast_map::NodeExpr(ref expr) => {
12341234
match expr.node {
1235-
ast::ExprFnBlock(_, ref fn_decl, ref top_level_block) |
12361235
ast::ExprProc(ref fn_decl, ref top_level_block) |
1237-
ast::ExprUnboxedFn(_, _, ref fn_decl, ref top_level_block) => {
1236+
ast::ExprClosure(_, _, ref fn_decl, ref top_level_block) => {
12381237
let name = format!("fn{}", token::gensym("fn"));
12391238
let name = token::str_to_ident(name.as_slice());
12401239
(name, &**fn_decl,
@@ -1310,7 +1309,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
13101309
file_metadata,
13111310
&mut function_name);
13121311

1313-
// There is no ast_map::Path for ast::ExprFnBlock-type functions. For now,
1312+
// There is no ast_map::Path for ast::ExprClosure-type functions. For now,
13141313
// just don't put them into a namespace. In the future this could be improved
13151314
// somehow (storing a path in the ast_map, or construct a path using the
13161315
// enclosing function).
@@ -3578,9 +3577,8 @@ fn populate_scope_map(cx: &CrateContext,
35783577
})
35793578
}
35803579

3581-
ast::ExprFnBlock(_, ref decl, ref block) |
35823580
ast::ExprProc(ref decl, ref block) |
3583-
ast::ExprUnboxedFn(_, _, ref decl, ref block) => {
3581+
ast::ExprClosure(_, _, ref decl, ref block) => {
35843582
with_new_scope(cx,
35853583
block.span,
35863584
scope_stack,

0 commit comments

Comments
 (0)