mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 17:12:53 +00:00
make parser disambiguate fn~ at top level correctly
This commit is contained in:
parent
263f4c58a0
commit
8818f42b19
@ -2166,13 +2166,24 @@ fn parse_fn_ty_proto(p: parser) -> ast::proto {
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_expr_lookahead(tok: token::token) -> bool {
|
||||
alt tok {
|
||||
token::LPAREN. | token::AT. | token::TILDE. | token::BINOP(_) {
|
||||
true
|
||||
}
|
||||
_ {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
|
||||
if eat_word(p, "const") {
|
||||
ret some(parse_item_const(p, attrs));
|
||||
} else if eat_word(p, "inline") {
|
||||
expect_word(p, "fn");
|
||||
ret some(parse_item_fn(p, ast::impure_fn, attrs));
|
||||
} else if is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN {
|
||||
} else if is_word(p, "fn") && !fn_expr_lookahead(p.look_ahead(1u)) {
|
||||
p.bump();
|
||||
ret some(parse_item_fn(p, ast::impure_fn, attrs));
|
||||
} else if eat_word(p, "pure") {
|
||||
|
@ -5,11 +5,11 @@ tag maybe_pointy {
|
||||
|
||||
type pointy = {
|
||||
mutable a : maybe_pointy,
|
||||
d : sendfn() -> uint,
|
||||
d : fn~() -> uint,
|
||||
};
|
||||
|
||||
fn make_uniq_closure<A:send>(a: A) -> sendfn() -> uint {
|
||||
sendfn() -> uint { ptr::addr_of(a) as uint }
|
||||
fn make_uniq_closure<A:send>(a: A) -> fn~() -> uint {
|
||||
fn~() -> uint { ptr::addr_of(a) as uint }
|
||||
}
|
||||
|
||||
fn empty_pointy() -> @pointy {
|
||||
|
@ -6,14 +6,14 @@ tag maybe_pointy {
|
||||
type pointy = {
|
||||
mutable a : maybe_pointy,
|
||||
c : ~int,
|
||||
d : sendfn()->(),
|
||||
d : fn~()->(),
|
||||
};
|
||||
|
||||
fn empty_pointy() -> @pointy {
|
||||
ret @{
|
||||
mutable a : none,
|
||||
c : ~22,
|
||||
d : sendfn()->(){},
|
||||
d : fn~()->(){},
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user