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

File tree

27 files changed

+126
-187
lines changed

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

0 commit comments

Comments
 (0)