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 | |
| parent | 9c88e5ef5a7e9c8db4ac56d53ba48c454b8b2010 (diff) | |
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')
| -rw-r--r-- | src/librustsyntax/ast_util.rs | 14 | ||||
| -rw-r--r-- | src/librustsyntax/attr.rs | 12 | ||||
| -rw-r--r-- | src/librustsyntax/codemap.rs | 2 | ||||
| -rw-r--r-- | src/librustsyntax/diagnostic.rs | 2 | ||||
| -rw-r--r-- | src/librustsyntax/ext/build.rs | 2 | ||||
| -rw-r--r-- | src/librustsyntax/ext/concat_idents.rs | 2 | ||||
| -rw-r--r-- | src/librustsyntax/ext/fmt.rs | 8 | ||||
| -rw-r--r-- | src/librustsyntax/ext/simplext.rs | 12 | ||||
| -rw-r--r-- | src/librustsyntax/fold.rs | 2 | ||||
| -rw-r--r-- | src/librustsyntax/parse/eval.rs | 2 | ||||
| -rw-r--r-- | src/librustsyntax/parse/parser.rs | 22 | ||||
| -rw-r--r-- | src/librustsyntax/print/pprust.rs | 48 | ||||
| -rw-r--r-- | src/librustsyntax/visit.rs | 68 |
13 files changed, 99 insertions, 97 deletions
diff --git a/src/librustsyntax/ast_util.rs b/src/librustsyntax/ast_util.rs index 5e0f1c89817..63c46b63341 100644 --- a/src/librustsyntax/ast_util.rs +++ b/src/librustsyntax/ast_util.rs @@ -142,11 +142,11 @@ fn float_ty_to_str(t: float_ty) -> str { fn is_exported(i: ident, m: _mod) -> bool { let mut local = false; let mut parent_enum : option<ident> = none; - for it: @item in m.items { + for m.items.each {|it| if it.ident == i { local = true; } alt it.node { item_enum(variants, _) { - for v: variant in variants { + for variants.each {|v| if v.node.name == i { local = true; parent_enum = some(it.ident); @@ -158,11 +158,11 @@ fn is_exported(i: ident, m: _mod) -> bool { if local { break; } } let mut has_explicit_exports = false; - for vi: @view_item in m.view_items { + for m.view_items.each {|vi| alt vi.node { view_item_export(vps) { has_explicit_exports = true; - for vp in vps { + for vps.each {|vp| alt vp.node { ast::view_path_simple(id, _, _) { if id == i { ret true; } @@ -177,7 +177,7 @@ fn is_exported(i: ident, m: _mod) -> bool { ast::view_path_list(path, ids, _) { if vec::len(*path) == 1u { if i == path[0] { ret true; } - for id in ids { + for ids.each {|id| if id.node.name == i { ret true; } } } else { @@ -278,14 +278,14 @@ fn public_methods(ms: [@method]) -> [@method] { fn split_class_items(cs: [@class_member]) -> ([ivar], [@method]) { let mut vs = [], ms = []; - for c in cs { + for cs.each {|c| alt c.node { instance_var(i, t, cm, id, privacy) { vs += [{ident: i, ty: t, cm: cm, id: id, privacy: privacy}]; } class_method(m) { ms += [m]; } } - } + }; (vs, ms) } diff --git a/src/librustsyntax/attr.rs b/src/librustsyntax/attr.rs index 3c6d69fc278..861e86ec0ee 100644 --- a/src/librustsyntax/attr.rs +++ b/src/librustsyntax/attr.rs @@ -46,7 +46,7 @@ fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] { fn find_linkage_attrs(attrs: [ast::attribute]) -> [ast::attribute] { let mut found = []; - for attr: ast::attribute in find_attrs_by_name(attrs, "link") { + for find_attrs_by_name(attrs, "link").each {|attr| alt attr.node.value.node { ast::meta_list(_, _) { found += [attr] } _ { #debug("ignoring link attribute that has incorrect type"); } @@ -150,7 +150,7 @@ fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value } // Get the meta_items from inside a vector of attributes fn attr_metas(attrs: [ast::attribute]) -> [@ast::meta_item] { let mut mitems = []; - for a: ast::attribute in attrs { mitems += [attr_meta(a)]; } + for attrs.each {|a| mitems += [attr_meta(a)]; } ret mitems; } @@ -178,7 +178,7 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { fn contains(haystack: [@ast::meta_item], needle: @ast::meta_item) -> bool { #debug("looking for %s", print::pprust::meta_item_to_str(*needle)); - for item: @ast::meta_item in haystack { + for haystack.each {|item| #debug("looking in %s", print::pprust::meta_item_to_str(*item)); if eq(item, needle) { #debug("found it!"); ret true; } @@ -207,12 +207,12 @@ fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] { // This is sort of stupid here, converting to a vec of mutables and back let mut v: [mut @ast::meta_item] = [mut]; - for mi: @ast::meta_item in items { v += [mut mi]; } + for items.each {|mi| v += [mut mi]; } std::sort::quick_sort(lteq, v); let mut v2: [@ast::meta_item] = []; - for mi: @ast::meta_item in v { v2 += [mi]; } + for v.each {|mi| v2 += [mi]; } ret v2; } @@ -231,7 +231,7 @@ fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) -> fn require_unique_names(diagnostic: span_handler, metas: [@ast::meta_item]) { let map = map::str_hash(); - for meta: @ast::meta_item in metas { + for metas.each {|meta| let name = get_meta_item_name(meta); if map.contains_key(name) { diagnostic.span_fatal(meta.span, diff --git a/src/librustsyntax/codemap.rs b/src/librustsyntax/codemap.rs index a1a117201fb..8e034690167 100644 --- a/src/librustsyntax/codemap.rs +++ b/src/librustsyntax/codemap.rs @@ -187,7 +187,7 @@ fn get_snippet(cm: codemap::codemap, fidx: uint, lo: uint, hi: uint) -> str } fn get_filemap(cm: codemap, filename: str) -> filemap { - for fm: filemap in cm.files { if fm.name == filename { ret fm; } } + for cm.files.each {|fm| if fm.name == filename { ret fm; } } //XXjdm the following triggers a mismatched type bug // (or expected function, found _|_) fail; // ("asking for " + filename + " which we don't know about"); diff --git a/src/librustsyntax/diagnostic.rs b/src/librustsyntax/diagnostic.rs index e29c11cbb11..be4905333c3 100644 --- a/src/librustsyntax/diagnostic.rs +++ b/src/librustsyntax/diagnostic.rs @@ -201,7 +201,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span, elided = true; } // Print the offending lines - for line: uint in display_lines { + for display_lines.each {|line| io::stderr().write_str(#fmt["%s:%u ", fm.name, line + 1u]); let s = codemap::get_line(fm, line as int) + "\n"; io::stderr().write_str(s); diff --git a/src/librustsyntax/ext/build.rs b/src/librustsyntax/ext/build.rs index 238cf40a685..a3b7f2ebbbb 100644 --- a/src/librustsyntax/ext/build.rs +++ b/src/librustsyntax/ext/build.rs @@ -68,7 +68,7 @@ fn mk_rec_e(cx: ext_ctxt, sp: span, fields: [{ident: ast::ident, ex: @ast::expr}]) -> @ast::expr { let mut astfields: [ast::field] = []; - for field: {ident: ast::ident, ex: @ast::expr} in fields { + for fields.each {|field| let ident = field.ident; let val = field.ex; let astfield = diff --git a/src/librustsyntax/ext/concat_idents.rs b/src/librustsyntax/ext/concat_idents.rs index f7bc95bd181..58577eb2e08 100644 --- a/src/librustsyntax/ext/concat_idents.rs +++ b/src/librustsyntax/ext/concat_idents.rs @@ -11,7 +11,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, } }; let mut res: ast::ident = ""; - for e: @ast::expr in args { + for args.each {|e| res += expr_to_ident(cx, e, "expected an ident"); } diff --git a/src/librustsyntax/ext/fmt.rs b/src/librustsyntax/ext/fmt.rs index 24657f8634b..6b00059080e 100644 --- a/src/librustsyntax/ext/fmt.rs +++ b/src/librustsyntax/ext/fmt.rs @@ -57,7 +57,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr]) fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: conv) -> @ast::expr { fn make_flags(cx: ext_ctxt, sp: span, flags: [flag]) -> @ast::expr { let mut flagexprs: [@ast::expr] = []; - for f: flag in flags { + for flags.each {|f| let mut fstr; alt f { flag_left_justify { fstr = "flag_left_justify"; } @@ -141,7 +141,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr]) option::none { } _ { cx.span_unimpl(sp, unsupported); } } - for f: flag in cnv.flags { + for cnv.flags.each {|f| alt f { flag_left_justify { } flag_sign_always { @@ -197,7 +197,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr]) some(p) { log(debug, "param: " + int::to_str(p, 10u)); } _ { #debug("param: none"); } } - for f: flag in c.flags { + for c.flags.each {|f| alt f { flag_left_justify { #debug("flag: left justify"); } flag_left_zero_pad { #debug("flag: left zero pad"); } @@ -252,7 +252,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr]) let mut n = 0u; let mut tmp_expr = mk_str(cx, sp, ""); let nargs = vec::len::<@ast::expr>(args); - for pc: piece in pieces { + for pieces.each {|pc| alt pc { piece_string(s) { let s_expr = mk_str(cx, fmt_sp, s); diff --git a/src/librustsyntax/ext/simplext.rs b/src/librustsyntax/ext/simplext.rs index 70bec007e17..eb031cfaf54 100644 --- a/src/librustsyntax/ext/simplext.rs +++ b/src/librustsyntax/ext/simplext.rs @@ -73,7 +73,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) -> {pre: [@expr], rep: option<@expr>, post: [@expr]} { let mut idx: uint = 0u; let mut res = none; - for elt: @expr in elts { + for elts.each {|elt| alt elt.node { expr_mac(m) { alt m.node { @@ -102,7 +102,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) -> fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: [T]) -> option<[U]> { let mut res = []; - for elem: T in v { + for v.each {|elem| alt f(elem) { none { ret none; } some(fv) { res += [fv]; } } } ret some(res); @@ -163,7 +163,7 @@ selectors. */ fn use_selectors_to_bind(b: binders, e: @expr) -> option<bindings> { let res = str_hash::<arb_depth<matchable>>(); //need to do this first, to check vec lengths. - for sel: selector in b.literal_ast_matchers { + for b.literal_ast_matchers.each {|sel| alt sel(match_expr(e)) { none { ret none; } _ { } } } let mut never_mind: bool = false; @@ -209,7 +209,7 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr { fn follow(m: arb_depth<matchable>, idx_path: @mut [uint]) -> arb_depth<matchable> { let mut res: arb_depth<matchable> = m; - for idx: uint in *idx_path { + for vec::each(*idx_path) {|idx| alt res { leaf(_) { ret res;/* end of the line */ } seq(new_ms, _) { res = new_ms[idx]; } @@ -677,7 +677,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, let mut macro_name: option<str> = none; let mut clauses: [@clause] = []; - for arg: @expr in args { + for args.each {|arg| alt arg.node { expr_vec(elts, mutbl) { if vec::len(elts) != 2u { @@ -753,7 +753,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, fn generic_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body, clauses: [@clause]) -> @expr { let arg = get_mac_arg(cx,sp,arg); - for c: @clause in clauses { + for clauses.each {|c| alt use_selectors_to_bind(c.params, arg) { some(bindings) { ret transcribe(cx, bindings, c.body); } none { cont; } diff --git a/src/librustsyntax/fold.rs b/src/librustsyntax/fold.rs index a24a08cdd09..ca690c55ade 100644 --- a/src/librustsyntax/fold.rs +++ b/src/librustsyntax/fold.rs @@ -338,7 +338,7 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { } pat_rec(fields, etc) { let mut fs = []; - for f: ast::field_pat in fields { + for fields.each {|f| fs += [{ident: f.ident, pat: fld.fold_pat(f.pat)}]; } pat_rec(fs, etc) 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) { diff --git a/src/librustsyntax/print/pprust.rs b/src/librustsyntax/print/pprust.rs index 58fd96bbb2e..ef0e512bbfe 100644 --- a/src/librustsyntax/print/pprust.rs +++ b/src/librustsyntax/print/pprust.rs @@ -269,7 +269,7 @@ fn synth_comment(s: ps, text: str) { fn commasep<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN)) { box(s, 0u, b); let mut first = true; - for elt: IN in elts { + for elts.each {|elt| if first { first = false; } else { word_space(s, ","); } op(s, elt); } @@ -282,7 +282,7 @@ fn commasep_cmnt<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN), box(s, 0u, b); let len = vec::len::<IN>(elts); let mut i = 0u; - for elt: IN in elts { + for elts.each {|elt| maybe_print_comment(s, get_span(elt).hi); op(s, elt); i += 1u; @@ -303,18 +303,18 @@ fn commasep_exprs(s: ps, b: breaks, exprs: [@ast::expr]) { fn print_mod(s: ps, _mod: ast::_mod, attrs: [ast::attribute]) { print_inner_attributes(s, attrs); - for vitem: @ast::view_item in _mod.view_items { + for _mod.view_items.each {|vitem| print_view_item(s, vitem); } - for item: @ast::item in _mod.items { print_item(s, item); } + for _mod.items.each {|item| print_item(s, item); } } fn print_native_mod(s: ps, nmod: ast::native_mod, attrs: [ast::attribute]) { print_inner_attributes(s, attrs); - for vitem: @ast::view_item in nmod.view_items { + for nmod.view_items.each {|vitem| print_view_item(s, vitem); } - for item: @ast::native_item in nmod.items { print_native_item(s, item); } + for nmod.items.each {|item| print_native_item(s, item); } } fn print_region(s: ps, region: ast::region) { @@ -476,7 +476,7 @@ fn print_item(s: ps, &&item: @ast::item) { end(s); } else { bopen(s); - for v: ast::variant in variants { + for variants.each {|v| space_if_not_bol(s); maybe_print_comment(s, v.span.lo); print_outer_attributes(s, v.node.attrs); @@ -500,7 +500,7 @@ fn print_item(s: ps, &&item: @ast::item) { print_fn_args_and_ret(s, ctor.node.dec); space(s.s); print_block(s, ctor.node.body); - for ci in items { + for items.each {|ci| /* FIXME: collect all private items and print them in a single "priv" section @@ -556,7 +556,7 @@ fn print_item(s: ps, &&item: @ast::item) { print_type(s, ty); space(s.s); bopen(s); - for meth in methods { + for methods.each {|meth| print_method(s, meth); } bclose(s, item.span); @@ -567,7 +567,7 @@ fn print_item(s: ps, &&item: @ast::item) { print_type_params(s, tps); word(s.s, " "); bopen(s); - for meth in methods { print_ty_method(s, meth); } + for methods.each {|meth| print_ty_method(s, meth); } bclose(s, item.span); } ast::item_res(decl, tps, body, dt_id, ct_id) { @@ -629,7 +629,7 @@ fn print_method(s: ps, meth: @ast::method) { fn print_outer_attributes(s: ps, attrs: [ast::attribute]) { let mut count = 0; - for attr: ast::attribute in attrs { + for attrs.each {|attr| alt attr.node.style { ast::attr_outer { print_attribute(s, attr); count += 1; } _ {/* fallthrough */ } @@ -640,7 +640,7 @@ fn print_outer_attributes(s: ps, attrs: [ast::attribute]) { fn print_inner_attributes(s: ps, attrs: [ast::attribute]) { let mut count = 0; - for attr: ast::attribute in attrs { + for attrs.each {|attr| alt attr.node.style { ast::attr_inner { print_attribute(s, attr); @@ -716,8 +716,8 @@ fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type, print_inner_attributes(s, attrs); - for vi in blk.node.view_items { print_view_item(s, vi); } - for st: @ast::stmt in blk.node.stmts { + for blk.node.view_items.each {|vi| print_view_item(s, vi); } + for blk.node.stmts.each {|st| print_stmt(s, *st); } alt blk.node.expr { @@ -957,12 +957,12 @@ fn print_expr(s: ps, &&expr: @ast::expr) { print_maybe_parens_discrim(s, expr); space(s.s); bopen(s); - for arm: ast::arm in arms { + for arms.each {|arm| space(s.s); cbox(s, alt_indent_unit); ibox(s, 0u); let mut first = true; - for p: @ast::pat in arm.pats { + for arm.pats.each {|p| if first { first = false; } else { space(s.s); word_space(s, "|"); } @@ -1189,7 +1189,7 @@ fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) { maybe_print_comment(s, path.span.lo); if path.node.global { word(s.s, "::"); } let mut first = true; - for id: ast::ident in path.node.idents { + for path.node.idents.each {|id| if first { first = false; } else { word(s.s, "::"); } word(s.s, id); } @@ -1359,7 +1359,7 @@ fn print_arg_mode(s: ps, m: ast::mode) { fn print_bounds(s: ps, bounds: @[ast::ty_param_bound]) { if vec::len(*bounds) > 0u { word(s.s, ":"); - for bound in *bounds { + for vec::each(*bounds) {|bound| nbsp(s); alt bound { ast::bound_copy { word(s.s, "copy"); } @@ -1403,7 +1403,7 @@ fn print_meta_item(s: ps, &&item: @ast::meta_item) { fn print_simple_path(s: ps, path: ast::simple_path) { let mut first = true; - for id in path { + for path.each {|id| if first { first = false; } else { word(s.s, "::"); } word(s.s, id); } @@ -1472,7 +1472,7 @@ fn print_view_item(s: ps, item: @ast::view_item) { // FIXME: The fact that this builds up the table anew for every call is // not good. Eventually, table should be a const. fn operator_prec(op: ast::binop) -> int { - for spec: parse::parser::op_spec in *parse::parser::prec_table() { + for vec::each(*parse::parser::prec_table()) {|spec| if spec.op == op { ret spec.prec; } } core::unreachable(); @@ -1667,7 +1667,7 @@ fn print_comment(s: ps, cmnt: lexer::cmnt) { } lexer::isolated { pprust::hardbreak_if_not_bol(s); - for line: str in cmnt.lines { + for cmnt.lines.each {|line| // Don't print empty lines because they will end up as trailing // whitespace if str::is_not_empty(line) { word(s.s, line); } @@ -1681,7 +1681,7 @@ fn print_comment(s: ps, cmnt: lexer::cmnt) { hardbreak(s.s); } else { ibox(s, 0u); - for line: str in cmnt.lines { + for cmnt.lines.each {|line| if str::is_not_empty(line) { word(s.s, line); } hardbreak(s.s); } @@ -1752,7 +1752,7 @@ fn constr_args_to_str<T>(f: fn@(T) -> str, args: [@ast::sp_constr_arg<T>]) -> str { let mut comma = false; let mut s = "("; - for a: @ast::sp_constr_arg<T> in args { + for args.each {|a| if comma { s += ", "; } else { comma = true; } s += constr_arg_to_str::<T>(f, a.node); } @@ -1795,7 +1795,7 @@ fn ty_constr_to_str(&&c: @ast::ty_constr) -> str { fn constrs_str<T>(constrs: [T], elt: fn(T) -> str) -> str { let mut s = "", colon = true; - for c in constrs { + for constrs.each {|c| if colon { s += " : "; colon = false; } else { s += ", "; } s += elt(c); } diff --git a/src/librustsyntax/visit.rs b/src/librustsyntax/visit.rs index c4e5da66743..fbeae7bc5a9 100644 --- a/src/librustsyntax/visit.rs +++ b/src/librustsyntax/visit.rs @@ -84,7 +84,7 @@ fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { alt cd.node { cdir_src_mod(_, _) { } cdir_dir_mod(_, cdirs, _) { - for cdir: @crate_directive in cdirs { + for cdirs.each {|cdir| visit_crate_directive(cdir, e, v); } } @@ -94,8 +94,8 @@ fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { } fn visit_mod<E>(m: _mod, _sp: span, _id: node_id, e: E, v: vt<E>) { - for vi: @view_item in m.view_items { v.visit_view_item(vi, e, v); } - for i: @item in m.items { v.visit_item(i, e, v); } + for m.view_items.each {|vi| v.visit_view_item(vi, e, v); } + for m.items.each {|i| v.visit_item(i, e, v); } } fn visit_view_item<E>(_vi: @view_item, _e: E, _v: vt<E>) { } @@ -114,8 +114,8 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) { } item_mod(m) { v.visit_mod(m, i.span, i.id, e, v); } item_native_mod(nm) { - for vi: @view_item in nm.view_items { v.visit_view_item(vi, e, v); } - for ni: @native_item in nm.items { v.visit_native_item(ni, e, v); } + for nm.view_items.each {|vi| v.visit_view_item(vi, e, v); } + for nm.items.each {|ni| v.visit_native_item(ni, e, v); } } item_ty(t, tps) { v.visit_ty(t, e, v); v.visit_ty_params(tps, e, v); } item_res(decl, tps, body, dtor_id, _) { @@ -124,21 +124,21 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) { } item_enum(variants, tps) { v.visit_ty_params(tps, e, v); - for vr: variant in variants { - for va: variant_arg in vr.node.args { v.visit_ty(va.ty, e, v); } + for variants.each {|vr| + for vr.node.args.each {|va| v.visit_ty(va.ty, e, v); } } } item_impl(tps, ifce, ty, methods) { v.visit_ty_params(tps, e, v); alt ifce { some(ty) { v.visit_ty(ty, e, v); } none {} } v.visit_ty(ty, e, v); - for m in methods { + for methods.each {|m| visit_method_helper(m, e, v) } } item_class(tps, members, ctor) { v.visit_ty_params(tps, e, v); - for m in members { + for members.each {|m| v.visit_class_item(m, e, v); } // make up a fake fn so as to call visit_fn on the ctor @@ -147,8 +147,8 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) { } item_iface(tps, methods) { v.visit_ty_params(tps, e, v); - for m in methods { - for a in m.decl.inputs { v.visit_ty(a.ty, e, v); } + for methods.each {|m| + for m.decl.inputs.each {|a| v.visit_ty(a.ty, e, v); } v.visit_ty(m.decl.output, e, v); } } @@ -176,12 +176,12 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) { ty_ptr(mt) { v.visit_ty(mt.ty, e, v); } ty_rptr(_, mt) { v.visit_ty(mt.ty, e, v); } ty_rec(flds) { - for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); } + for flds.each {|f| v.visit_ty(f.node.mt.ty, e, v); } } - ty_tup(ts) { for tt in ts { v.visit_ty(tt, e, v); } } + ty_tup(ts) { for ts.each {|tt| v.visit_ty(tt, e, v); } } ty_fn(_, decl) { - for a in decl.inputs { v.visit_ty(a.ty, e, v); } - for c: @constr in decl.constraints { + for decl.inputs.each {|a| v.visit_ty(a.ty, e, v); } + for decl.constraints.each {|c| v.visit_constr(c.node.path, c.span, c.node.id, e, v); } v.visit_ty(decl.output, e, v); @@ -189,7 +189,7 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) { ty_path(p, _) { visit_path(p, e, v); } ty_constr(t, cs) { v.visit_ty(t, e, v); - for tc: @spanned<constr_general_<@path, node_id>> in cs { + for cs.each {|tc| v.visit_constr(tc.node.path, tc.span, tc.node.id, e, v); } } @@ -207,19 +207,19 @@ fn visit_constr<E>(_operator: @path, _sp: span, _id: node_id, _e: E, } fn visit_path<E>(p: @path, e: E, v: vt<E>) { - for tp: @ty in p.node.types { v.visit_ty(tp, e, v); } + for p.node.types.each {|tp| v.visit_ty(tp, e, v); } } fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { alt p.node { pat_enum(path, children) { visit_path(path, e, v); - for child: @pat in children { v.visit_pat(child, e, v); } + for children.each {|child| v.visit_pat(child, e, v); } } pat_rec(fields, _) { - for f: field_pat in fields { v.visit_pat(f.pat, e, v); } + for fields.each {|f| v.visit_pat(f.pat, e, v); } } - pat_tup(elts) { for elt in elts { v.visit_pat(elt, e, v); } } + pat_tup(elts) { for elts.each {|elt| v.visit_pat(elt, e, v); } } pat_box(inner) | pat_uniq(inner) { v.visit_pat(inner, e, v); } @@ -243,8 +243,8 @@ fn visit_native_item<E>(ni: @native_item, e: E, v: vt<E>) { } fn visit_ty_params<E>(tps: [ty_param], e: E, v: vt<E>) { - for tp in tps { - for bound in *tp.bounds { + for tps.each {|tp| + for vec::each(*tp.bounds) {|bound| alt bound { bound_iface(t) { v.visit_ty(t, e, v); } bound_copy | bound_send { } @@ -254,8 +254,8 @@ fn visit_ty_params<E>(tps: [ty_param], e: E, v: vt<E>) { } fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) { - for a: arg in fd.inputs { v.visit_ty(a.ty, e, v); } - for c: @constr in fd.constraints { + for fd.inputs.each {|a| v.visit_ty(a.ty, e, v); } + for fd.constraints.each {|c| v.visit_constr(c.node.path, c.span, c.node.id, e, v); } v.visit_ty(fd.output, e, v); @@ -278,8 +278,8 @@ fn visit_fn<E>(fk: fn_kind, decl: fn_decl, body: blk, _sp: span, } fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) { - for vi in b.node.view_items { v.visit_view_item(vi, e, v); } - for s in b.node.stmts { v.visit_stmt(s, e, v); } + for b.node.view_items.each {|vi| v.visit_view_item(vi, e, v); } + for b.node.stmts.each {|s| v.visit_stmt(s, e, v); } visit_expr_opt(b.node.expr, e, v); } @@ -294,7 +294,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { alt d.node { decl_local(locs) { - for loc in locs { v.visit_local(loc, e, v); } + for locs.each {|loc| v.visit_local(loc, e, v); } } decl_item(it) { v.visit_item(it, e, v); } } @@ -305,7 +305,7 @@ fn visit_expr_opt<E>(eo: option<@expr>, e: E, v: vt<E>) { } fn visit_exprs<E>(exprs: [@expr], e: E, v: vt<E>) { - for ex: @expr in exprs { v.visit_expr(ex, e, v); } + for exprs.each {|ex| v.visit_expr(ex, e, v); } } fn visit_mac<E>(m: mac, e: E, v: vt<E>) { @@ -328,17 +328,17 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { } expr_vec(es, _) { visit_exprs(es, e, v); } expr_rec(flds, base) { - for f: field in flds { v.visit_expr(f.node.expr, e, v); } + for flds.each {|f| v.visit_expr(f.node.expr, e, v); } visit_expr_opt(base, e, v); } - expr_tup(elts) { for el in elts { v.visit_expr(el, e, v); } } + expr_tup(elts) { for elts.each {|el| v.visit_expr(el, e, v); } } expr_call(callee, args, _) { visit_exprs(args, e, v); v.visit_expr(callee, e, v); } expr_bind(callee, args) { v.visit_expr(callee, e, v); - for eo: option<@expr> in args { visit_expr_opt(eo, e, v); } + for args.each {|eo| visit_expr_opt(eo, e, v); } } expr_binary(_, a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } expr_addr_of(_, x) | expr_unary(_, x) | expr_loop_body(x) | @@ -367,7 +367,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { expr_do_while(b, x) { v.visit_block(b, e, v); v.visit_expr(x, e, v); } expr_alt(x, arms, _) { v.visit_expr(x, e, v); - for a: arm in arms { v.visit_arm(a, e, v); } + for arms.each {|a| v.visit_arm(a, e, v); } } expr_fn(proto, decl, body, _) { v.visit_fn(fk_anon(proto), decl, body, ex.span, ex.id, e, v); @@ -386,7 +386,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { } expr_field(x, _, tys) { v.visit_expr(x, e, v); - for tp in tys { v.visit_ty(tp, e, v); } + for tys.each {|tp| v.visit_ty(tp, e, v); } } expr_index(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } expr_path(p) { visit_path(p, e, v); } @@ -404,7 +404,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { } fn visit_arm<E>(a: arm, e: E, v: vt<E>) { - for p: @pat in a.pats { v.visit_pat(p, e, v); } + for a.pats.each {|p| v.visit_pat(p, e, v); } visit_expr_opt(a.guard, e, v); v.visit_block(a.body, e, v); } |
