@@ -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_view_item ( _vi : @ast:: view_item ,
@@ -34,18 +35,44 @@ fn fn_usage_expr(expr: @ast::expr,
34
35
_ { }
35
36
}
36
37
}
38
+ if !ctx. generic_bare_fn_legal
39
+ && ty:: expr_has_ty_params ( ctx. tcx , expr) {
40
+ alt ty:: struct ( ctx. tcx , ty:: expr_ty ( ctx. tcx , expr) ) {
41
+ ty:: ty_fn ( ast:: proto_bare. , _, _, _, _) {
42
+ ctx. tcx . sess . span_fatal (
43
+ expr. span ,
44
+ "generic bare functions can only be called or bound" ) ;
45
+ }
46
+ _ { }
47
+ }
48
+ }
37
49
}
38
50
39
51
ast:: expr_call ( f, args) {
40
- let f_ctx = { unsafe_fn_legal: true with ctx} ;
52
+ let f_ctx = { unsafe_fn_legal: true,
53
+ generic_bare_fn_legal: true with ctx} ;
41
54
visit:: visit_expr ( f, f_ctx, v) ;
42
55
43
- let args_ctx = { unsafe_fn_legal: false with ctx} ;
56
+ let args_ctx = { unsafe_fn_legal: false,
57
+ generic_bare_fn_legal: false with ctx} ;
44
58
visit:: visit_exprs ( args, args_ctx, v) ;
45
59
}
46
60
61
+ ast:: expr_bind ( f, args) {
62
+ let f_ctx = { unsafe_fn_legal: false,
63
+ generic_bare_fn_legal: true with ctx} ;
64
+ v. visit_expr ( f, f_ctx, v) ;
65
+
66
+ let args_ctx = { unsafe_fn_legal: false,
67
+ generic_bare_fn_legal: false with ctx} ;
68
+ for arg in args {
69
+ visit:: visit_expr_opt ( arg, args_ctx, v) ;
70
+ }
71
+ }
72
+
47
73
_ {
48
- let subctx = { unsafe_fn_legal : false with ctx} ;
74
+ let subctx = { unsafe_fn_legal : false ,
75
+ generic_bare_fn_legal : false with ctx} ;
49
76
visit:: visit_expr ( expr, subctx, v) ;
50
77
}
51
78
}
@@ -57,7 +84,11 @@ fn check_crate_fn_usage(tcx: ty::ctxt, crate: @ast::crate) {
57
84
@{ visit_expr: fn_usage_expr,
58
85
visit_view_item: fn_usage_view_item
59
86
with * visit:: default_visitor ( ) } ) ;
60
- let ctx = { tcx: tcx, unsafe_fn_legal: false } ;
87
+ let ctx = {
88
+ tcx: tcx,
89
+ unsafe_fn_legal: false ,
90
+ generic_bare_fn_legal: false
91
+ } ;
61
92
visit:: visit_crate ( * crate , ctx, visit) ;
62
93
}
63
94
0 commit comments