Skip to content

Commit 7f1ea3e

Browse files
committed
Don't allow binding patterns to bind keywords
Closes #1586
1 parent fe8a31e commit 7f1ea3e

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

src/comp/syntax/parse/parser.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,15 @@ fn parse_path(p: parser) -> @ast::path {
666666
{global: global, idents: ids, types: []});
667667
}
668668

669+
fn parse_value_path(p: parser) -> @ast::path {
670+
let pt = parse_path(p);
671+
let last_word = pt.node.idents[vec::len(pt.node.idents)-1u];
672+
if p.bad_expr_words.contains_key(last_word) {
673+
p.fatal("found " + last_word + " in expression position");
674+
}
675+
pt
676+
}
677+
669678
fn parse_path_and_ty_param_substs(p: parser, colons: bool) -> @ast::path {
670679
let lo = p.span.lo;
671680
let path = parse_path(p);
@@ -1510,11 +1519,11 @@ fn parse_pat(p: parser) -> @ast::pat {
15101519
pat = ast::pat_lit(val);
15111520
}
15121521
} else if is_plain_ident(p) &&
1513-
alt p.look_ahead(1u) {
1514-
token::LPAREN | token::LBRACKET | token::LT { false }
1515-
_ { true }
1516-
} {
1517-
let name = parse_path(p);
1522+
alt p.look_ahead(1u) {
1523+
token::LPAREN | token::LBRACKET | token::LT { false }
1524+
_ { true }
1525+
} {
1526+
let name = parse_value_path(p);
15181527
let sub = if eat(p, token::AT) { some(parse_pat(p)) }
15191528
else { none };
15201529
pat = ast::pat_ident(name, sub);

src/test/compile-fail/reference-in-loop.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test/run-pass/reference-branch.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)