diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2011-12-11 20:51:14 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2011-12-14 14:32:21 -0800 |
| commit | ba6da950f1034c62c5d64d200dd2d7c2222e9729 (patch) | |
| tree | 6f093fa8411ec99673bc1a3e3b59f8aa89d88eb0 /src/comp/middle | |
| parent | 6a8cb704d9c2543cb30df2e26b992c17e3bc488d (diff) | |
| download | rust-ba6da950f1034c62c5d64d200dd2d7c2222e9729.tar.gz rust-ba6da950f1034c62c5d64d200dd2d7c2222e9729.zip | |
restore old functionality for now
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/fn_usage.rs | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/comp/middle/fn_usage.rs b/src/comp/middle/fn_usage.rs index 2dc585a6106..1bf9533f080 100644 --- a/src/comp/middle/fn_usage.rs +++ b/src/comp/middle/fn_usage.rs @@ -7,7 +7,8 @@ export check_crate_fn_usage; type fn_usage_ctx = { tcx: ty::ctxt, - unsafe_fn_legal: bool + unsafe_fn_legal: bool, + generic_bare_fn_legal: bool }; fn fn_usage_expr(expr: @ast::expr, @@ -28,28 +29,44 @@ fn fn_usage_expr(expr: @ast::expr, _ {} } } + if !ctx.generic_bare_fn_legal + && ty::expr_has_ty_params(ctx.tcx, expr) { + alt ty::struct(ctx.tcx, ty::expr_ty(ctx.tcx, expr)) { + ty::ty_fn(ast::proto_bare., _, _, _, _) { + ctx.tcx.sess.span_fatal( + expr.span, + "generic bare functions can only be called or bound"); + } + _ { } + } + } } ast::expr_call(f, args, _) { - let f_ctx = {unsafe_fn_legal: true with ctx}; + let f_ctx = {unsafe_fn_legal: true, + generic_bare_fn_legal: true with ctx}; v.visit_expr(f, f_ctx, v); - let args_ctx = {unsafe_fn_legal: false with ctx}; + let args_ctx = {unsafe_fn_legal: false, + generic_bare_fn_legal: false with ctx}; visit::visit_exprs(args, args_ctx, v); } ast::expr_bind(f, args) { - let f_ctx = {unsafe_fn_legal: false with ctx}; + let f_ctx = {unsafe_fn_legal: false, + generic_bare_fn_legal: true with ctx}; v.visit_expr(f, f_ctx, v); - let args_ctx = {unsafe_fn_legal: false with ctx}; + let args_ctx = {unsafe_fn_legal: false, + generic_bare_fn_legal: false with ctx}; for arg in args { visit::visit_expr_opt(arg, args_ctx, v); } } _ { - let subctx = {unsafe_fn_legal: false with ctx}; + let subctx = {unsafe_fn_legal: false, + generic_bare_fn_legal: false with ctx}; visit::visit_expr(expr, subctx, v); } } @@ -62,7 +79,8 @@ fn check_crate_fn_usage(tcx: ty::ctxt, crate: @ast::crate) { with *visit::default_visitor()}); let ctx = { tcx: tcx, - unsafe_fn_legal: false + unsafe_fn_legal: false, + generic_bare_fn_legal: false }; visit::visit_crate(*crate, ctx, visit); } |
