diff options
| author | bors <bors@rust-lang.org> | 2013-03-19 09:52:17 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-19 09:52:17 -0700 |
| commit | 3c84bac9462ae853b32f55fcaca2613a7e392d41 (patch) | |
| tree | 30290aecec90bcffd91a5d905256cd755e583bbe /src/libsyntax | |
| parent | e67448d397ed8f468170d6fba95ceae081ece624 (diff) | |
| parent | d7d17dc14e653332848f7f6f994b34eb7fc923ec (diff) | |
| download | rust-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')
| -rw-r--r-- | src/libsyntax/ast.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 5 |
5 files changed, 12 insertions, 23 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e5fb2ad153c..65eeff5bbab 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -386,7 +386,6 @@ pub enum vstore { #[auto_decode] #[deriving_eq] pub enum expr_vstore { - // FIXME (#3469): Change uint to @expr (actually only constant exprs) expr_vstore_fixed(Option<uint>), // [1,2,3,4] expr_vstore_uniq, // ~[1,2,3,4] expr_vstore_box, // @[1,2,3,4] @@ -916,7 +915,7 @@ pub enum ty_ { ty_box(mt), ty_uniq(mt), ty_vec(mt), - ty_fixed_length_vec(mt, uint), + ty_fixed_length_vec(mt, @expr), ty_ptr(mt), ty_rptr(Option<@Lifetime>, mt), ty_closure(@TyClosure), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index a8952f313a5..159b23f4f99 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -622,10 +622,10 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ { } ty_tup(ref tys) => ty_tup(tys.map(|ty| fld.fold_ty(*ty))), ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)), - ty_fixed_length_vec(ref mt, vs) => { + ty_fixed_length_vec(ref mt, e) => { ty_fixed_length_vec( fold_mt(mt, fld), - vs + fld.fold_expr(e) ) } ty_mac(ref mac) => ty_mac(fold_mac(*mac)) 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, © *self.token) - ) - ); - } - } + Some(self.parse_expr()) } else { None } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 71f3de17414..93583a1487a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -425,7 +425,7 @@ pub fn print_type_ex(s: @ps, &&ty: @ast::Ty, print_colons: bool) { } print_type(s, mt.ty); word(s.s, ~" * "); - word(s.s, fmt!("%u", v)); + print_expr(s, v); word(s.s, ~"]"); } ast::ty_mac(_) => { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 6a0f1a2ec46..a159c98d21b 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -246,7 +246,10 @@ pub fn visit_ty<E>(t: @Ty, e: E, v: vt<E>) { (v.visit_ty)(f.decl.output, e, v); }, ty_path(p, _) => visit_path(p, e, v), - ty_fixed_length_vec(ref mt, _) => (v.visit_ty)(mt.ty, e, v), + ty_fixed_length_vec(ref mt, ex) => { + (v.visit_ty)(mt.ty, e, v); + (v.visit_expr)(ex, e, v); + }, ty_nil | ty_bot | ty_mac(_) | ty_infer => () } } |
