From 4de0b3d9474eb4b1284a8abf4bd03a5135a19a83 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Wed, 27 Jul 2011 16:24:00 -0700 Subject: [PATCH] Allow already bound functions to be bound again. This commit just disables the check. All of the real work was in previous commits that moved the target function into the bindings part of the closure that is tracked by the tydesc. Closes #754. --- src/comp/middle/trans.rs | 4 ---- src/test/run-pass/rebind-fn.rs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 src/test/run-pass/rebind-fn.rs diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index e64b0d94b7c..b745ab8a6d3 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -4538,10 +4538,6 @@ fn trans_bind(cx: &@block_ctxt, f: &@ast::expr, fn trans_bind_1(cx: &@block_ctxt, f: &@ast::expr, f_res: &lval_result, args: &(option::t[@ast::expr])[], id: ast::node_id) -> result { - if f_res.is_mem { - bcx_ccx(cx).sess.unimpl("re-binding existing function"); - } - let bound: (@ast::expr)[] = ~[]; for argopt: option::t[@ast::expr] in args { alt argopt { none. { } some(e) { bound += ~[e]; } } diff --git a/src/test/run-pass/rebind-fn.rs b/src/test/run-pass/rebind-fn.rs new file mode 100644 index 00000000000..b20a0315ba6 --- /dev/null +++ b/src/test/run-pass/rebind-fn.rs @@ -0,0 +1,12 @@ +// xfail-stage0 +fn add(i: int, j: int) -> int { ret i + j; } +fn binder(n: int) -> fn() -> int { + let f = bind add(n, _); + ret bind f(2); +} +fn main() { + binder(5); + let f = binder(1); + assert(f() == 3); + assert(binder(8)() == 10); +}