Skip to content

Commit b0340ec

Browse files
committed
Don't allow bind to produce bare functions
Issue rust-lang#1022
1 parent 47e9ab6 commit b0340ec

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/comp/middle/typeck.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,18 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21162116
}
21172117
i += 1u;
21182118
}
2119-
let ft = ty::mk_fn(tcx, proto, out_args, rt, cf, constrs);
2119+
2120+
// Determine what fn prototype results from binding
2121+
fn lower_bound_proto(proto: ast::proto) -> ast::proto {
2122+
// FIXME: This is right for bare fns, possibly not others
2123+
alt proto {
2124+
ast::proto_bare. { ast::proto_fn }
2125+
_ { proto }
2126+
}
2127+
}
2128+
2129+
let ft = ty::mk_fn(tcx, lower_bound_proto(proto),
2130+
out_args, rt, cf, constrs);
21202131
write::ty_only_fixup(fcx, id, ft);
21212132
}
21222133
ast::expr_call(f, args) {

src/test/compile-fail/fn-bare-bind.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// error-pattern:mismatched types: expected fn#() but found fn()
2+
3+
fn# f() {
4+
}
5+
6+
fn main() {
7+
// Can't produce a bare function by binding
8+
let g: fn#() = bind f();
9+
}

0 commit comments

Comments
 (0)