Skip to content

Commit 565b39b

Browse files
committed
rename iter2 to each2, make it follow iterator protocol
1 parent fd8e7aa commit 565b39b

File tree

12 files changed

+28
-23
lines changed

12 files changed

+28
-23
lines changed

src/libcore/vec.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export swap;
8282
export reverse;
8383
export reversed;
8484
export each, each_mut, each_const, eachi, rev_each, rev_eachi;
85-
export iter2;
85+
export each2;
8686
export permute;
8787
export windowed;
8888
export as_imm_buf;
@@ -1266,10 +1266,12 @@ pure fn rev_eachi<T>(v: &r/[T], blk: fn(i: uint, v: &r/T) -> bool) {
12661266
* Both vectors must have the same length
12671267
*/
12681268
#[inline]
1269-
fn iter2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T)) {
1269+
fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) {
12701270
assert len(v1) == len(v2);
12711271
for uint::range(0u, len(v1)) |i| {
1272-
f(&v1[i], &v2[i])
1272+
if !f(&v1[i], &v2[i]) {
1273+
return;
1274+
}
12731275
}
12741276
}
12751277

src/libsyntax/ext/auto_serialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
566566
tp_inputs);
567567

568568
let tps_map = map::HashMap();
569-
do vec::iter2(tps, tp_inputs) |tp, arg| {
569+
for vec::each2(tps, tp_inputs) |tp, arg| {
570570
let arg_ident = arg.ident;
571571
tps_map.insert(
572572
tp.ident,
@@ -773,7 +773,7 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
773773
tp_inputs);
774774

775775
let tps_map = map::HashMap();
776-
do vec::iter2(tps, tp_inputs) |tp, arg| {
776+
for vec::each2(tps, tp_inputs) |tp, arg| {
777777
let arg_ident = arg.ident;
778778
tps_map.insert(
779779
tp.ident,

src/rustc/middle/borrowck/check_loans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl check_loan_ctxt {
524524
let arg_tys =
525525
ty::ty_fn_args(
526526
ty::node_id_to_type(self.tcx(), callee_id));
527-
do vec::iter2(args, arg_tys) |arg, arg_ty| {
527+
for vec::each2(args, arg_tys) |arg, arg_ty| {
528528
match ty::resolved_mode(self.tcx(), arg_ty.mode) {
529529
ast::by_move => {
530530
self.check_move_out(*arg);

src/rustc/middle/borrowck/gather_loans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn req_loans_in_expr(ex: @ast::expr,
113113
ast::expr_call(f, args, _) => {
114114
let arg_tys = ty::ty_fn_args(ty::expr_ty(self.tcx(), f));
115115
let scope_r = ty::re_scope(ex.id);
116-
do vec::iter2(args, arg_tys) |arg, arg_ty| {
116+
for vec::each2(args, arg_tys) |arg, arg_ty| {
117117
match ty::resolved_mode(self.tcx(), arg_ty.mode) {
118118
ast::by_mutbl_ref => {
119119
let arg_cmt = self.bccx.cat_expr(*arg);

src/rustc/middle/kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
272272
tys_to_str(cx.tcx, *ts), ts.len(),
273273
*bounds, (*bounds).len());
274274
}
275-
do vec::iter2(*ts, *bounds) |ty, bound| {
275+
for vec::each2(*ts, *bounds) |ty, bound| {
276276
check_bounds(cx, id_to_use, e.span, *ty, *bound)
277277
}
278278
}
@@ -376,7 +376,7 @@ fn check_ty(aty: @ty, cx: ctx, v: visit::vt<ctx>) {
376376
do option::iter(&cx.tcx.node_type_substs.find(id)) |ts| {
377377
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id));
378378
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
379-
do vec::iter2(*ts, *bounds) |ty, bound| {
379+
for vec::each2(*ts, *bounds) |ty, bound| {
380380
check_bounds(cx, aty.id, aty.span, *ty, *bound)
381381
}
382382
}

src/rustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl,
675675
match ty::get(fn_ty).sty {
676676
ty::ty_fn(fn_ty) => {
677677
let mut counter = 0;
678-
do vec::iter2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| {
678+
for vec::each2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| {
679679
counter += 1;
680680
debug!("arg %d, ty=%s, mode=%s",
681681
counter,

src/rustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
15711571

15721572
expr_call(f, args, _) => {
15731573
let targs = ty::ty_fn_args(ty::expr_ty(self.tcx, f));
1574-
do vec::iter2(args, targs) |arg_expr, arg_ty| {
1574+
for vec::each2(args, targs) |arg_expr, arg_ty| {
15751575
match ty::resolved_mode(self.tcx, arg_ty.mode) {
15761576
by_val | by_copy | by_ref | by_mutbl_ref => {}
15771577
by_move => {

src/rustc/middle/trans/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id)
4949
ast::item_enum(_, _) => {
5050
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
5151
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
52-
do vec::iter2(*vs_here, *vs_there) |here, there| {
52+
for vec::each2(*vs_here, *vs_there) |here, there| {
5353
if there.id == fn_id { my_id = here.id.node; }
5454
ccx.external.insert(there.id, Some(here.id.node));
5555
}

src/rustc/middle/trans/type_use.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ fn mark_for_expr(cx: ctx, e: @expr) {
204204
expr_path(_) => {
205205
do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| {
206206
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id));
207-
vec::iter2(type_uses_for(cx.ccx, id, ts.len()), *ts,
208-
|uses, subst| {
209-
type_needs(cx, *uses, *subst)
210-
})
207+
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
208+
for vec::each2(uses_for_ts, *ts) |uses, subst| {
209+
type_needs(cx, *uses, *subst)
210+
}
211211
}
212212
}
213213
expr_fn(*) | expr_fn_block(*) => {
@@ -238,8 +238,10 @@ fn mark_for_expr(cx: ctx, e: @expr) {
238238
match mth.origin {
239239
typeck::method_static(did) => {
240240
do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| {
241-
do vec::iter2(type_uses_for(cx.ccx, did, ts.len()), *ts)
242-
|uses, subst| { type_needs(cx, *uses, *subst)}
241+
let type_uses = type_uses_for(cx.ccx, did, ts.len());
242+
for vec::each2(type_uses, *ts) |uses, subst| {
243+
type_needs(cx, *uses, *subst)
244+
}
243245
}
244246
}
245247
typeck::method_param({param_num: param, _}) => {

src/rustc/middle/typeck/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fn check_fn(ccx: @crate_ctxt,
308308
for self_info.each |info| {
309309
fcx.write_ty(info.self_id, info.self_ty);
310310
}
311-
do vec::iter2(decl.inputs, arg_tys) |input, arg| {
311+
for vec::each2(decl.inputs, arg_tys) |input, arg| {
312312
fcx.write_ty(input.id, *arg);
313313
}
314314

@@ -351,7 +351,7 @@ fn check_fn(ccx: @crate_ctxt,
351351
}
352352

353353
// Add formal parameters.
354-
do vec::iter2(arg_tys, decl.inputs) |arg_ty, input| {
354+
for vec::each2(arg_tys, decl.inputs) |arg_ty, input| {
355355
assign(input.ty.span, input.id, Some(*arg_ty));
356356
debug!("Argument %s is assigned to %s",
357357
tcx.sess.str_of(input.ident),

src/rustc/middle/typeck/check/alt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
164164
}
165165
166166
do subpats.iter() |pats| {
167-
do vec::iter2(*pats, arg_types) |subpat, arg_ty| {
167+
for vec::each2(*pats, arg_types) |subpat, arg_ty| {
168168
check_pat(pcx, *subpat, *arg_ty);
169169
}
170170
};

src/rustc/middle/typeck/check/vtable.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,9 @@ fn connect_trait_tps(fcx: @fn_ctxt, expr: @ast::expr, impl_tys: ~[ty::t],
392392
ty::get(trait_ty).sty, impl_did);
393393
match ty::get(trait_ty).sty {
394394
ty::ty_trait(_, substs, _) => {
395-
vec::iter2(substs.tps, trait_tys,
396-
|a, b| demand::suptype(fcx, expr.span, *a, *b));
395+
for vec::each2(substs.tps, trait_tys) |a, b| {
396+
demand::suptype(fcx, expr.span, *a, *b)
397+
}
397398
}
398399
_ => tcx.sess.impossible_case(expr.span, "connect_trait_tps: \
399400
don't know how to handle a non-trait ty")

0 commit comments

Comments
 (0)