diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2012-04-06 20:01:43 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2012-04-06 20:38:23 +0200 |
| commit | c902eafa14803ca9fcb0b59ce852bdabca826c6f (patch) | |
| tree | 2e282ea67adaca64dd813a78d94a6cd3766a5dac /src/librustsyntax/parse | |
| parent | 9c88e5ef5a7e9c8db4ac56d53ba48c454b8b2010 (diff) | |
| download | rust-c902eafa14803ca9fcb0b59ce852bdabca826c6f.tar.gz rust-c902eafa14803ca9fcb0b59ce852bdabca826c6f.zip | |
Convert old-style for loops to new-style
Most could use the each method, but because of the hack used to disambiguate old- and new-style loops, some had to use vec::each. (This hack will go away soon.) Issue #1619
Diffstat (limited to 'src/librustsyntax/parse')
| -rw-r--r-- | src/librustsyntax/parse/eval.rs | 2 | ||||
| -rw-r--r-- | src/librustsyntax/parse/parser.rs | 22 |
2 files changed, 13 insertions, 11 deletions
diff --git a/src/librustsyntax/parse/eval.rs b/src/librustsyntax/parse/eval.rs index a9e0ce9845e..d01667d1029 100644 --- a/src/librustsyntax/parse/eval.rs +++ b/src/librustsyntax/parse/eval.rs @@ -13,7 +13,7 @@ type ctx = fn eval_crate_directives(cx: ctx, cdirs: [@ast::crate_directive], prefix: str, &view_items: [@ast::view_item], &items: [@ast::item]) { - for sub_cdir: @ast::crate_directive in cdirs { + for cdirs.each {|sub_cdir| eval_crate_directive(cx, sub_cdir, prefix, view_items, items); } } diff --git a/src/librustsyntax/parse/parser.rs b/src/librustsyntax/parse/parser.rs index 759ac1a3a95..c48d7b3c567 100644 --- a/src/librustsyntax/parse/parser.rs +++ b/src/librustsyntax/parse/parser.rs @@ -143,12 +143,13 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, // interpreted as a specific kind of statement, which would be confusing. fn bad_expr_word_table() -> hashmap<str, ()> { let words = str_hash(); - for word in ["alt", "assert", "be", "break", "check", "claim", - "class", "const", "cont", "copy", "crust", "do", "else", - "enum", "export", "fail", "fn", "for", "if", "iface", - "impl", "import", "let", "log", "loop", "mod", "mut", - "mut", "native", "pure", "resource", "ret", "trait", - "type", "unchecked", "unsafe", "while", "new"] { + let keys = ["alt", "assert", "be", "break", "check", "claim", + "class", "const", "cont", "copy", "crust", "do", "else", + "enum", "export", "fail", "fn", "for", "if", "iface", + "impl", "import", "let", "log", "loop", "mod", "mut", + "mut", "native", "pure", "resource", "ret", "trait", + "type", "unchecked", "unsafe", "while", "new"]; + for keys.each {|word| words.insert(word, ()); } words @@ -312,7 +313,7 @@ fn parse_ty_field(p: parser) -> ast::ty_field { // otherwise, fail fn ident_index(p: parser, args: [ast::arg], i: ast::ident) -> uint { let mut j = 0u; - for a: ast::arg in args { if a.ident == i { ret j; } j += 1u; } + for args.each {|a| if a.ident == i { ret j; } j += 1u; } p.fatal("unbound variable `" + i + "` in constraint arg"); } @@ -1230,7 +1231,7 @@ fn parse_more_binops(p: parser, plhs: pexpr, min_prec: int) -> let peeked = p.token; if peeked == token::BINOP(token::OR) && p.restriction == RESTRICT_NO_BAR_OP { ret lhs; } - for cur: op_spec in *p.precs { + for vec::each(*p.precs) {|cur| if cur.prec > min_prec && cur.tok == peeked { p.bump(); let expr = parse_prefix_expr(p); @@ -1414,7 +1415,7 @@ fn parse_for_expr(p: parser) -> @ast::expr { _ { false } }; if new_style { - let call = parse_expr(p); + let call = parse_expr_res(p, RESTRICT_STMT_EXPR); alt call.node { ast::expr_call(f, args, true) { let b_arg = vec::last(args); @@ -1428,6 +1429,7 @@ fn parse_for_expr(p: parser) -> @ast::expr { } } } else { + p.warn("old-style for"); let decl = parse_local(p, false, false); expect_word(p, "in"); let seq = parse_expr(p); @@ -2328,7 +2330,7 @@ fn parse_item_enum(p: parser, attrs: [ast::attribute]) -> @ast::item { let arg_tys = parse_seq(token::LPAREN, token::RPAREN, seq_sep(token::COMMA), {|p| parse_ty(p, false)}, p); - for ty in arg_tys.node { + for arg_tys.node.each {|ty| args += [{ty: ty, id: p.get_id()}]; } } else if eat(p, token::EQ) { |
