Skip to content

Commit a2a0ec3

Browse files
committed
---
yaml --- r: 6693 b: refs/heads/master c: ba6da95 h: refs/heads/master i: 6691: 118970c v: v3
1 parent b8045c5 commit a2a0ec3

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 6a8cb704d9c2543cb30df2e26b992c17e3bc488d
2+
refs/heads/master: ba6da950f1034c62c5d64d200dd2d7c2222e9729

trunk/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)