]> git.lizzy.rs Git - rust.git/commitdiff
treat fn*() as fn&()
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 18 Jan 2012 20:04:07 +0000 (12:04 -0800)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 19 Jan 2012 15:10:59 +0000 (07:10 -0800)
This is not my ideal way of going about things.  I'd prefer not
to have expressions typed as fn*(), for example, but I couldn't
get that to work together with inferring the modes of arguments
and other corner cases.

src/comp/middle/shape.rs
src/comp/middle/trans_closure.rs
src/comp/syntax/parse/parser.rs
src/test/run-pass/block-arg-used-as-any.rs [new file with mode: 0644]

index 9986400dfa32501871168f43bd8219ab033d96bd..bb3de341df1ed95401774a440031a1415fb35cbe 100644 (file)
@@ -432,7 +432,8 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
       ty::ty_fn({proto: ast::proto_uniq, _}) {
         s += [shape_uniq_fn];
       }
-      ty::ty_fn({proto: ast::proto_block, _}) {
+      ty::ty_fn({proto: ast::proto_block, _}) |
+      ty::ty_fn({proto: ast::proto_any, _}) {
         s += [shape_stack_fn];
       }
       ty::ty_fn({proto: ast::proto_bare, _}) {
index 1e58ea53f9f13c13d77ddc22db470481f85e8753..4915a975322f15719a8e89422c637a299a3a00a6 100644 (file)
@@ -528,8 +528,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
     };
 
     let closure = alt proto {
-      ast::proto_any { fail "proto_any cannot appear in an expr"; }
-      ast::proto_block { trans_closure_env(ty::ck_block) }
+      ast::proto_any | ast::proto_block { trans_closure_env(ty::ck_block) }
       ast::proto_box { trans_closure_env(ty::ck_box) }
       ast::proto_uniq { trans_closure_env(ty::ck_uniq) }
       ast::proto_bare {
index 0da193c20785b9ed1dade38f48b1e476b5545579..ee947772ab251336a7fb6d88bb879ce86e5f8958 100644 (file)
@@ -146,8 +146,8 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
     for word in ["mod", "if", "else", "while", "do", "alt", "for", "break",
                  "cont", "ret", "be", "fail", "type", "resource", "check",
                  "assert", "claim", "native", "fn", "pure",
-                 "unsafe", "block", "import", "export", "let", "const",
-                 "log", "copy", "sendfn", "impl", "iface", "enum"] {
+                 "unsafe", "import", "export", "let", "const",
+                 "log", "copy", "impl", "iface", "enum"] {
         words.insert(word, ());
     }
     words
@@ -493,9 +493,6 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
           _ { /* fallthrough */ }
         }
         t = parse_ty_fn(proto, p);
-    } else if eat_word(p, "block") {
-        //p.warn("block is deprecated, use fn& or fn");
-        t = parse_ty_fn(ast::proto_block, p);
     } else if eat_word(p, "native") {
         expect_word(p, "fn");
         t = parse_ty_fn(ast::proto_bare, p);
@@ -802,9 +799,6 @@ fn parse_bottom_expr(p: parser) -> pexpr {
           _ { /* fallthrough */ }
         }
         ret pexpr(parse_fn_expr(p, proto));
-    } else if eat_word(p, "block") {
-        p.warn("block is deprecated, use fn& or fn");
-        ret pexpr(parse_fn_expr(p, ast::proto_block));
     } else if eat_word(p, "unchecked") {
         ret pexpr(parse_block_expr(p, lo, ast::unchecked_blk));
     } else if eat_word(p, "unsafe") {
diff --git a/src/test/run-pass/block-arg-used-as-any.rs b/src/test/run-pass/block-arg-used-as-any.rs
new file mode 100644 (file)
index 0000000..3612875
--- /dev/null
@@ -0,0 +1,8 @@
+fn call_any(f: fn*() -> uint) -> uint {
+    ret f();
+}
+
+fn main() {
+    let x_r = call_any {|| 22u };
+    assert x_r == 22u;
+}