about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-03-19 09:52:17 -0700
committerbors <bors@rust-lang.org>2013-03-19 09:52:17 -0700
commit3c84bac9462ae853b32f55fcaca2613a7e392d41 (patch)
tree30290aecec90bcffd91a5d905256cd755e583bbe /src/libsyntax/parse
parente67448d397ed8f468170d6fba95ceae081ece624 (diff)
parentd7d17dc14e653332848f7f6f994b34eb7fc923ec (diff)
downloadrust-3c84bac9462ae853b32f55fcaca2613a7e392d41.tar.gz
rust-3c84bac9462ae853b32f55fcaca2613a7e392d41.zip
auto merge of #5112 : luqmana/rust/3469, r=graydon
So this is a partial fix for #3469. Partial because it only works for simple constant expressions like `32/2` and `2+2` and not for any actual constants.

For example:
```
const FOO: uint = 2+2;
let v: [int * FOO];
```

results in:
```
error: expected constant expr for vector length: Non-constant path in constant expr
```

This seems to be because at the point of error (`typeck::astconv`) the def_map doesn't contain the constant and thus it can't lookup the actual expression (`2+2` in this case).

So, feedback on what I have so far and suggestions for how to address the constant issue?
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 8a883b73a64..c7e93635d4c 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -642,7 +642,8 @@ pub impl Parser {
                 self.obsolete(*self.last_span, ObsoleteMutVector);
             }
 
-            // Parse the `* 3` in `[ int * 3 ]`
+            // Parse the `* e` in `[ int * e ]`
+            // where `e` is a const expression
             let t = match self.maybe_parse_fixed_vstore_with_star() {
                 None => ty_vec(mt),
                 Some(suffix) => ty_fixed_length_vec(mt, suffix)
@@ -814,23 +815,9 @@ pub impl Parser {
         })
     }
 
-    fn maybe_parse_fixed_vstore_with_star(&self) -> Option<uint> {
+    fn maybe_parse_fixed_vstore_with_star(&self) -> Option<@ast::expr> {
         if self.eat(&token::BINOP(token::STAR)) {
-            match *self.token {
-                token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 => {
-                    self.bump();
-                    Some(i as uint)
-                }
-                _ => {
-                    self.fatal(
-                        fmt!(
-                            "expected integral vector length \
-                            but found `%s`",
-                            token_to_str(self.reader, &copy *self.token)
-                        )
-                    );
-                }
-            }
+            Some(self.parse_expr())
         } else {
             None
         }