@@ -7,7 +7,8 @@ export check_crate_fn_usage;
7
7
8
8
type fn_usage_ctx = {
9
9
tcx : ty:: ctxt ,
10
- unsafe_fn_legal : bool
10
+ unsafe_fn_legal : bool ,
11
+ generic_bare_fn_legal : bool
11
12
} ;
12
13
13
14
fn fn_usage_expr ( expr : @ast:: expr ,
@@ -28,28 +29,44 @@ fn fn_usage_expr(expr: @ast::expr,
28
29
_ { }
29
30
}
30
31
}
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
+ }
31
43
}
32
44
33
45
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} ;
35
48
v. visit_expr ( f, f_ctx, v) ;
36
49
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} ;
38
52
visit:: visit_exprs ( args, args_ctx, v) ;
39
53
}
40
54
41
55
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} ;
43
58
v. visit_expr ( f, f_ctx, v) ;
44
59
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} ;
46
62
for arg in args {
47
63
visit:: visit_expr_opt ( arg, args_ctx, v) ;
48
64
}
49
65
}
50
66
51
67
_ {
52
- let subctx = { unsafe_fn_legal : false with ctx} ;
68
+ let subctx = { unsafe_fn_legal : false ,
69
+ generic_bare_fn_legal : false with ctx} ;
53
70
visit:: visit_expr ( expr, subctx, v) ;
54
71
}
55
72
}
@@ -62,7 +79,8 @@ fn check_crate_fn_usage(tcx: ty::ctxt, crate: @ast::crate) {
62
79
with * visit:: default_visitor ( ) } ) ;
63
80
let ctx = {
64
81
tcx: tcx,
65
- unsafe_fn_legal: false
82
+ unsafe_fn_legal: false ,
83
+ generic_bare_fn_legal: false
66
84
} ;
67
85
visit:: visit_crate ( * crate , ctx, visit) ;
68
86
}
0 commit comments