about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-02-10 15:48:25 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-02-10 15:54:47 +0100
commit7f1ea3ef6a92eb82ae66c47954ed955eba6028b1 (patch)
treefa460453d74fece88c5c3b59d60d3bc7df3bac5d /src
parentfe8a31e56992a712b532350596af05186ac90613 (diff)
downloadrust-7f1ea3ef6a92eb82ae66c47954ed955eba6028b1.tar.gz
rust-7f1ea3ef6a92eb82ae66c47954ed955eba6028b1.zip
Don't allow binding patterns to bind keywords
Closes #1586
Diffstat (limited to 'src')
-rw-r--r--src/comp/syntax/parse/parser.rs19
-rw-r--r--src/test/compile-fail/reference-in-loop.rs10
-rw-r--r--src/test/run-pass/reference-branch.rs9
3 files changed, 14 insertions, 24 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index d6c6a5edb96..8e2897407a3 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -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);
@@ -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);
diff --git a/src/test/compile-fail/reference-in-loop.rs b/src/test/compile-fail/reference-in-loop.rs
deleted file mode 100644
index 403e0bb07cb..00000000000
--- a/src/test/compile-fail/reference-in-loop.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-// error-pattern: overwriting x will invalidate reference y
-
-fn main() {
-    let x = [];
-    let &y = x;
-    while true {
-        log(error, y);
-        x = [1];
-    }
-}
diff --git a/src/test/run-pass/reference-branch.rs b/src/test/run-pass/reference-branch.rs
deleted file mode 100644
index 20e4f27627e..00000000000
--- a/src/test/run-pass/reference-branch.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-// Ensures that invalidating a reference in one branch doesn't
-// influence other branches.
-
-fn main() {
-    let x = [];
-    let &y = x;
-    if true { x = [1]; }
-    else { log(error, y); }
-}