Skip to content

Commit 1d81776

Browse files
committed
auto merge of #19113 : nikomatsakis/rust/unboxed-boxed-closure-unification, r=acrichto
Use the expected type to infer the argument/return types of unboxed closures. Also, in `||` expressions, use the expected type to decide if the result should be a boxed or unboxed closure (and if an unboxed closure, what kind). This supercedes PR #19089, which was already reviewed by @pcwalton.
2 parents b825b34 + b9c5cd4 commit 1d81776

34 files changed

+595
-344
lines changed

src/librustc/middle/borrowck/mod.rs

+6-3
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

+1-2
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

+2-3
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

+1-2
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

+5-6
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

+3-4
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

+4-9
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};
@@ -5848,24 +5848,19 @@ impl<'a> Resolver<'a> {
58485848
visit::walk_expr(self, expr);
58495849
}
58505850

5851-
ExprFnBlock(capture_clause, ref fn_decl, ref block) => {
5851+
ExprClosure(capture_clause, _, ref fn_decl, ref block) => {
58525852
self.capture_mode_map.insert(expr.id, capture_clause);
58535853
self.resolve_function(ClosureRibKind(expr.id, ast::DUMMY_NODE_ID),
58545854
Some(&**fn_decl), NoTypeParameters,
58555855
&**block);
58565856
}
5857+
58575858
ExprProc(ref fn_decl, ref block) => {
58585859
self.capture_mode_map.insert(expr.id, ast::CaptureByValue);
58595860
self.resolve_function(ClosureRibKind(expr.id, block.id),
58605861
Some(&**fn_decl), NoTypeParameters,
58615862
&**block);
58625863
}
5863-
ExprUnboxedFn(capture_clause, _, ref fn_decl, ref block) => {
5864-
self.capture_mode_map.insert(expr.id, capture_clause);
5865-
self.resolve_function(ClosureRibKind(expr.id, block.id),
5866-
Some(&**fn_decl), NoTypeParameters,
5867-
&**block);
5868-
}
58695864

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

src/librustc/middle/traits/fulfill.rs

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ impl<'tcx> FulfillmentContext<'tcx> {
109109
self.select(&mut selcx, false)
110110
}
111111

112+
pub fn pending_trait_obligations(&self) -> &[Obligation<'tcx>] {
113+
self.trait_obligations[]
114+
}
115+
112116
fn select<'a>(&mut self,
113117
selcx: &mut SelectionContext<'a, 'tcx>,
114118
only_new_obligations: bool)

src/librustc/middle/ty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3919,9 +3919,8 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
39193919
ast::ExprTup(..) |
39203920
ast::ExprIf(..) |
39213921
ast::ExprMatch(..) |
3922-
ast::ExprFnBlock(..) |
3922+
ast::ExprClosure(..) |
39233923
ast::ExprProc(..) |
3924-
ast::ExprUnboxedFn(..) |
39253924
ast::ExprBlock(..) |
39263925
ast::ExprRepeat(..) |
39273926
ast::ExprVec(..) => {

src/librustc/middle/typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
995995
}
996996
ast::TyInfer => {
997997
// TyInfer also appears as the type of arguments or return
998-
// values in a ExprFnBlock, ExprProc, or ExprUnboxedFn, or as
998+
// values in a ExprClosure or ExprProc, or as
999999
// the type of local variables. Both of these cases are
10001000
// handled specially and will not descend into this routine.
10011001
this.ty_infer(ast_ty.span)

0 commit comments

Comments
 (0)