Skip to content

Commit

Permalink
Don't allow binding patterns to bind keywords
Browse files Browse the repository at this point in the history
Closes #1586
  • Loading branch information
marijnh committed Feb 10, 2012
1 parent fe8a31e commit 7f1ea3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
19 changes: 14 additions & 5 deletions src/comp/syntax/parse/parser.rs
Expand Up @@ -666,6 +666,15 @@ fn parse_path(p: parser) -> @ast::path {
{global: global, idents: ids, types: []});
}

fn parse_value_path(p: parser) -> @ast::path {
let pt = parse_path(p);
let last_word = pt.node.idents[vec::len(pt.node.idents)-1u];
if p.bad_expr_words.contains_key(last_word) {
p.fatal("found " + last_word + " in expression position");
}
pt
}

fn parse_path_and_ty_param_substs(p: parser, colons: bool) -> @ast::path {
let lo = p.span.lo;
let path = parse_path(p);
Expand Down Expand Up @@ -1510,11 +1519,11 @@ fn parse_pat(p: parser) -> @ast::pat {
pat = ast::pat_lit(val);
}
} else if is_plain_ident(p) &&
alt p.look_ahead(1u) {
token::LPAREN | token::LBRACKET | token::LT { false }
_ { true }
} {
let name = parse_path(p);
alt p.look_ahead(1u) {
token::LPAREN | token::LBRACKET | token::LT { false }
_ { true }
} {
let name = parse_value_path(p);
let sub = if eat(p, token::AT) { some(parse_pat(p)) }
else { none };
pat = ast::pat_ident(name, sub);
Expand Down
10 changes: 0 additions & 10 deletions src/test/compile-fail/reference-in-loop.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/run-pass/reference-branch.rs

This file was deleted.

0 comments on commit 7f1ea3e

Please sign in to comment.