Skip to content

Commit 8818f42

Browse files
committed
make parser disambiguate fn~ at top level correctly
1 parent 263f4c5 commit 8818f42

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/comp/syntax/parse/parser.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2166,13 +2166,24 @@ fn parse_fn_ty_proto(p: parser) -> ast::proto {
21662166
}
21672167
}
21682168

2169+
fn fn_expr_lookahead(tok: token::token) -> bool {
2170+
alt tok {
2171+
token::LPAREN. | token::AT. | token::TILDE. | token::BINOP(_) {
2172+
true
2173+
}
2174+
_ {
2175+
false
2176+
}
2177+
}
2178+
}
2179+
21692180
fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
21702181
if eat_word(p, "const") {
21712182
ret some(parse_item_const(p, attrs));
21722183
} else if eat_word(p, "inline") {
21732184
expect_word(p, "fn");
21742185
ret some(parse_item_fn(p, ast::impure_fn, attrs));
2175-
} else if is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN {
2186+
} else if is_word(p, "fn") && !fn_expr_lookahead(p.look_ahead(1u)) {
21762187
p.bump();
21772188
ret some(parse_item_fn(p, ast::impure_fn, attrs));
21782189
} else if eat_word(p, "pure") {

src/test/run-pass/uniq-cc-generic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ tag maybe_pointy {
55

66
type pointy = {
77
mutable a : maybe_pointy,
8-
d : sendfn() -> uint,
8+
d : fn~() -> uint,
99
};
1010

11-
fn make_uniq_closure<A:send>(a: A) -> sendfn() -> uint {
12-
sendfn() -> uint { ptr::addr_of(a) as uint }
11+
fn make_uniq_closure<A:send>(a: A) -> fn~() -> uint {
12+
fn~() -> uint { ptr::addr_of(a) as uint }
1313
}
1414

1515
fn empty_pointy() -> @pointy {

src/test/run-pass/uniq-cc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ tag maybe_pointy {
66
type pointy = {
77
mutable a : maybe_pointy,
88
c : ~int,
9-
d : sendfn()->(),
9+
d : fn~()->(),
1010
};
1111

1212
fn empty_pointy() -> @pointy {
1313
ret @{
1414
mutable a : none,
1515
c : ~22,
16-
d : sendfn()->(){},
16+
d : fn~()->(){},
1717
}
1818
}
1919

0 commit comments

Comments
 (0)