diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index ee947772ab2..a5980465048 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -146,8 +146,8 @@ fn bad_expr_word_table() -> hashmap { for word in ["mod", "if", "else", "while", "do", "alt", "for", "break", "cont", "ret", "be", "fail", "type", "resource", "check", "assert", "claim", "native", "fn", "pure", - "unsafe", "import", "export", "let", "const", - "log", "copy", "impl", "iface", "enum"] { + "unsafe", "block", "import", "export", "let", "const", + "log", "copy", "sendfn", "impl", "iface", "enum"] { words.insert(word, ()); } words @@ -493,6 +493,9 @@ 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); @@ -799,6 +802,9 @@ 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") { @@ -2109,12 +2115,8 @@ fn parse_fn_ty_proto(p: parser) -> ast::proto { p.bump(); ast::proto_block } - token::BINOP(token::STAR) { - p.bump(); // temporary: fn* for any closure - ast::proto_any - } _ { - ast::proto_bare + ast::proto_any } } } diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index f4aa5646d0b..d666e0e3fab 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1643,7 +1643,7 @@ fn opt_proto_to_str(opt_p: option) -> str { fn proto_to_str(p: ast::proto) -> str { ret alt p { ast::proto_bare { "native fn" } - ast::proto_any { "fn*" } + ast::proto_any { "fn" } ast::proto_block { "fn&" } ast::proto_uniq { "fn~" } ast::proto_box { "fn@" } diff --git a/src/test/compile-fail/block-coerce-no-2.rs b/src/test/compile-fail/block-coerce-no-2.rs index 926e39529ea..0ef325aadd3 100644 --- a/src/test/compile-fail/block-coerce-no-2.rs +++ b/src/test/compile-fail/block-coerce-no-2.rs @@ -1,14 +1,13 @@ -// error-pattern: mismatched types - // Make sure that fn-to-block coercion isn't incorrectly lifted over // other tycons. fn main() { - fn f(f: fn(fn(fn()))) { + fn f(f: native fn(native fn(native fn()))) { } - fn g(f: fn(block())) { + fn g(f: native fn(fn())) { } f(g); + //!^ ERROR mismatched types: expected `native fn(native fn(native fn()))` } diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs index 2985d98a34a..42c893a2064 100644 --- a/src/test/compile-fail/block-coerce-no.rs +++ b/src/test/compile-fail/block-coerce-no.rs @@ -1,16 +1,16 @@ -// error-pattern: mismatched types - // Make sure that fn-to-block coercion isn't incorrectly lifted over // other tycons. -fn coerce(b: block()) -> fn() { - fn lol(f: fn(block()) -> fn(), g: block()) -> fn() { ret f(g); } - fn fn_id(f: fn()) -> fn() { ret f } +fn coerce(b: fn()) -> native fn() { + fn lol(f: native fn(block()) -> native fn(), + g: fn()) -> native fn() { ret f(g); } + fn fn_id(f: native fn()) -> native fn() { ret f } ret lol(fn_id, b); + //!^ ERROR mismatched types: expected `native fn(fn&()) -> native fn()` } - fn main() { let i = 8; - let f = coerce(block () { log(error, i); }); - f(); } + let f = coerce({|| log(error, i); }); + f(); +} diff --git a/src/test/pretty/fn-types.rs b/src/test/pretty/fn-types.rs new file mode 100644 index 00000000000..f0e48076416 --- /dev/null +++ b/src/test/pretty/fn-types.rs @@ -0,0 +1,8 @@ +// pp-exact + +fn from_native_fn(x: native fn()) { } +fn from_closure(x: fn()) { } +fn from_stack_closure(x: fn&()) { } +fn from_box_closure(x: fn@()) { } +fn from_unique_closure(x: fn~()) { } +fn main() { } diff --git a/src/test/run-pass/block-arg-used-as-any.rs b/src/test/run-pass/block-arg-used-as-any.rs index 3612875f2d3..a13e03d94ce 100644 --- a/src/test/run-pass/block-arg-used-as-any.rs +++ b/src/test/run-pass/block-arg-used-as-any.rs @@ -1,4 +1,4 @@ -fn call_any(f: fn*() -> uint) -> uint { +fn call_any(f: fn() -> uint) -> uint { ret f(); }