allow binding of fn~, make result fn@. fixes 1899.

This commit is contained in:
Niko Matsakis 2012-03-16 17:27:42 -04:00
parent f80008f04b
commit e399ddbf17
3 changed files with 8 additions and 24 deletions

View File

@ -2609,8 +2609,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
}
let proto = alt proto {
ast::proto_bare | ast::proto_box { ast::proto_box }
ast::proto_uniq | ast::proto_any | ast::proto_block {
ast::proto_bare | ast::proto_box | ast::proto_uniq {
ast::proto_box
}
ast::proto_any | ast::proto_block {
tcx.sess.span_err(expr.span,
#fmt["cannot bind %s closures",
proto_to_str(proto)]);

View File

@ -1,22 +0,0 @@
// -*- rust -*-
// I originally made this test to ensure that bind does the right
// thing when binding a unique closure (which is to copy the closure,
// I suppose?). But I've since decided it's not worth the effort, and
// so I just made it a simple error. But I left the test as is in
// case we ever decide that bind should work with unique closures,
// though a simpler test would suffice for now.
fn make_addr(-x: ~int) -> fn~() -> uint {
(fn~[move x]() -> uint { ptr::addr_of(*x) as uint })
}
fn main() {
let x = ~3;
let a = ptr::addr_of(*x) as uint;
let adder: fn~() -> uint = make_addr(x);
let bound_adder: fn~() -> uint = bind adder();
//!^ ERROR cannot bind fn~ closures
assert adder() == a;
assert bound_adder() != a;
}

View File

@ -0,0 +1,4 @@
fn main()
{
let _b = [bind (fn~() {})()];
}