Skip to content

Commit ba6da95

Browse files
committed
restore old functionality for now
1 parent 6a8cb70 commit ba6da95

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/comp/middle/fn_usage.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export check_crate_fn_usage;
77

88
type fn_usage_ctx = {
99
tcx: ty::ctxt,
10-
unsafe_fn_legal: bool
10+
unsafe_fn_legal: bool,
11+
generic_bare_fn_legal: bool
1112
};
1213

1314
fn fn_usage_expr(expr: @ast::expr,
@@ -28,28 +29,44 @@ fn fn_usage_expr(expr: @ast::expr,
2829
_ {}
2930
}
3031
}
32+
if !ctx.generic_bare_fn_legal
33+
&& ty::expr_has_ty_params(ctx.tcx, expr) {
34+
alt ty::struct(ctx.tcx, ty::expr_ty(ctx.tcx, expr)) {
35+
ty::ty_fn(ast::proto_bare., _, _, _, _) {
36+
ctx.tcx.sess.span_fatal(
37+
expr.span,
38+
"generic bare functions can only be called or bound");
39+
}
40+
_ { }
41+
}
42+
}
3143
}
3244

3345
ast::expr_call(f, args, _) {
34-
let f_ctx = {unsafe_fn_legal: true with ctx};
46+
let f_ctx = {unsafe_fn_legal: true,
47+
generic_bare_fn_legal: true with ctx};
3548
v.visit_expr(f, f_ctx, v);
3649

37-
let args_ctx = {unsafe_fn_legal: false with ctx};
50+
let args_ctx = {unsafe_fn_legal: false,
51+
generic_bare_fn_legal: false with ctx};
3852
visit::visit_exprs(args, args_ctx, v);
3953
}
4054

4155
ast::expr_bind(f, args) {
42-
let f_ctx = {unsafe_fn_legal: false with ctx};
56+
let f_ctx = {unsafe_fn_legal: false,
57+
generic_bare_fn_legal: true with ctx};
4358
v.visit_expr(f, f_ctx, v);
4459

45-
let args_ctx = {unsafe_fn_legal: false with ctx};
60+
let args_ctx = {unsafe_fn_legal: false,
61+
generic_bare_fn_legal: false with ctx};
4662
for arg in args {
4763
visit::visit_expr_opt(arg, args_ctx, v);
4864
}
4965
}
5066

5167
_ {
52-
let subctx = {unsafe_fn_legal: false with ctx};
68+
let subctx = {unsafe_fn_legal: false,
69+
generic_bare_fn_legal: false with ctx};
5370
visit::visit_expr(expr, subctx, v);
5471
}
5572
}
@@ -62,7 +79,8 @@ fn check_crate_fn_usage(tcx: ty::ctxt, crate: @ast::crate) {
6279
with *visit::default_visitor()});
6380
let ctx = {
6481
tcx: tcx,
65-
unsafe_fn_legal: false
82+
unsafe_fn_legal: false,
83+
generic_bare_fn_legal: false
6684
};
6785
visit::visit_crate(*crate, ctx, visit);
6886
}

0 commit comments

Comments
 (0)