diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index 7ea6de90fb2..892908dc0a0 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -351,6 +351,7 @@ a single large vector of floats. Each task needs the full vector to perform its # use std::vec; # use std::uint; # use std::rand; +# use std::iterator::IteratorUtil; use extra::arc::ARC; fn pnorm(nums: &~[float], p: uint) -> float { diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index b50c158f37a..98f8efb72c8 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -19,6 +19,7 @@ use middle::typeck::method_map; use middle::moves; use util::ppaux::ty_to_str; +use core::iterator::IteratorUtil; use core::uint; use core::vec; use extra::sort; @@ -242,7 +243,7 @@ pub fn is_useful(cx: @MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful { not_useful } ty::ty_unboxed_vec(*) | ty::ty_evec(*) => { - let max_len = do m.foldr(0) |r, max_len| { + let max_len = do m.rev_iter().fold(0) |max_len, r| { match r[0].node { pat_vec(ref before, _, ref after) => { uint::max(before.len() + after.len(), max_len) diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 3097be242a1..8a9a67db802 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -110,6 +110,7 @@ use middle::ty; use middle::typeck; use middle::moves; +use core::iterator::IteratorUtil; use core::cast::transmute; use core::hashmap::HashMap; use core::io; @@ -923,7 +924,7 @@ impl Liveness { pub fn propagate_through_block(&self, blk: &blk, succ: LiveNode) -> LiveNode { let succ = self.propagate_through_opt_expr(blk.node.expr, succ); - do blk.node.stmts.foldr(succ) |stmt, succ| { + do blk.node.stmts.rev_iter().fold(succ) |succ, stmt| { self.propagate_through_stmt(*stmt, succ) } } @@ -977,7 +978,7 @@ impl Liveness { pub fn propagate_through_exprs(&self, exprs: &[@expr], succ: LiveNode) -> LiveNode { - do exprs.foldr(succ) |expr, succ| { + do exprs.rev_iter().fold(succ) |succ, expr| { self.propagate_through_expr(*expr, succ) } } @@ -1021,7 +1022,7 @@ impl Liveness { // the construction of a closure itself is not important, // but we have to consider the closed over variables. let caps = self.ir.captures(expr); - do caps.foldr(succ) |cap, succ| { + do caps.rev_iter().fold(succ) |succ, cap| { self.init_from_succ(cap.ln, succ); let var = self.variable(cap.var_nid, expr.span); self.acc(cap.ln, var, ACC_READ | ACC_USE); @@ -1159,7 +1160,7 @@ impl Liveness { expr_struct(_, ref fields, with_expr) => { let succ = self.propagate_through_opt_expr(with_expr, succ); - do (*fields).foldr(succ) |field, succ| { + do fields.rev_iter().fold(succ) |succ, field| { self.propagate_through_expr(field.node.expr, succ) } } @@ -1215,10 +1216,10 @@ impl Liveness { } expr_inline_asm(ref ia) =>{ - let succ = do ia.inputs.foldr(succ) |&(_, expr), succ| { + let succ = do ia.inputs.rev_iter().fold(succ) |succ, &(_, expr)| { self.propagate_through_expr(expr, succ) }; - do ia.outputs.foldr(succ) |&(_, expr), succ| { + do ia.outputs.rev_iter().fold(succ) |succ, &(_, expr)| { self.propagate_through_expr(expr, succ) } } diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index b26f80fc355..8e1b165f408 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -44,6 +44,7 @@ * taken to it, implementing them for Rust seems difficult. */ +use core::iterator::IteratorUtil; use core::container::Map; use core::libc::c_ulonglong; use core::option::{Option, Some, None}; @@ -176,7 +177,7 @@ fn represent_type_uncached(cx: @CrateContext, t: ty::t) -> Repr { // Since there's at least one // non-empty body, explicit discriminants should have // been rejected by a checker before this point. - if !cases.alli(|i,c| c.discr == (i as int)) { + if !cases.iter().enumerate().all(|(i,c)| c.discr == (i as int)) { cx.sess.bug(fmt!("non-C-like enum %s with specified \ discriminants", ty::item_path_str(cx.tcx, def_id))) diff --git a/src/librustc/middle/trans/cabi_arm.rs b/src/librustc/middle/trans/cabi_arm.rs index 1fecdf5a338..d59635ccd76 100644 --- a/src/librustc/middle/trans/cabi_arm.rs +++ b/src/librustc/middle/trans/cabi_arm.rs @@ -20,7 +20,6 @@ use middle::trans::common::{T_array, T_ptr, T_void}; use core::iterator::IteratorUtil; use core::option::{Option, None, Some}; use core::uint; -use core::vec; fn align_up_to(off: uint, a: uint) -> uint { return (off + a - 1u) / a * a; diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 7540f54f308..bdc9fd0ccad 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1821,11 +1821,9 @@ pub trait ImmutableVector<'self, T> { fn last_opt(&self) -> Option<&'self T>; fn position(&self, f: &fn(t: &T) -> bool) -> Option; fn rposition(&self, f: &fn(t: &T) -> bool) -> Option; - fn foldr<'a, U>(&'a self, z: U, p: &fn(t: &'a T, u: U) -> U) -> U; fn map(&self, f: &fn(t: &T) -> U) -> ~[U]; fn mapi(&self, f: &fn(uint, t: &T) -> U) -> ~[U]; fn map_r(&self, f: &fn(x: &T) -> U) -> ~[U]; - fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool; fn flat_map(&self, f: &fn(t: &T) -> ~[U]) -> ~[U]; fn filter_mapped(&self, f: &fn(t: &T) -> Option) -> ~[U]; unsafe fn unsafe_ref(&self, index: uint) -> *T; @@ -1913,12 +1911,6 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { rposition(*self, f) } - /// Reduce a vector from right to left - #[inline] - fn foldr<'a, U>(&'a self, z: U, p: &fn(t: &'a T, u: U) -> U) -> U { - self.rev_iter().fold(z, |u, t| p(t, u)) - } - /// Apply a function to each element of a vector and return the results #[inline] fn map(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) } @@ -1942,14 +1934,6 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { r } - /** - * Returns true if the function returns true for all elements. - * - * If the vector is empty, true is returned. - */ - fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool { - self.iter().enumerate().all(|(i, t)| f(i,t)) - } /** * Apply a function to each element of a vector and return a concatenation * of each result vector diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index d99363d7ee5..d170ca92678 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -20,6 +20,7 @@ use opt_vec; use parse::token; use visit; +use core::iterator::IteratorUtil; use core::hashmap::HashMap; use core::int; use core::option; @@ -833,7 +834,7 @@ mod test { // returning the resulting index fn unfold_test_sc(tscs : ~[TestSC], tail: SyntaxContext, table : &mut SCTable) -> SyntaxContext { - tscs.foldr(tail, |tsc : &TestSC,tail : SyntaxContext| + tscs.rev_iter().fold(tail, |tail : SyntaxContext, tsc : &TestSC| {match *tsc { M(mrk) => new_mark_internal(mrk,tail,table), R(ident,name) => new_rename_internal(ident,name,tail,table)}}) @@ -874,7 +875,7 @@ mod test { // extend a syntax context with a sequence of marks given // in a vector. v[0] will be the outermost mark. fn unfold_marks(mrks:~[Mrk],tail:SyntaxContext,table: &mut SCTable) -> SyntaxContext { - mrks.foldr(tail, |mrk:&Mrk,tail:SyntaxContext| + mrks.rev_iter().fold(tail, |tail:SyntaxContext, mrk:&Mrk| {new_mark_internal(*mrk,tail,table)}) } diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index b36d4496492..078fd4231ca 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -1025,11 +1025,11 @@ pub fn cs_fold(use_foldl: bool, match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { if use_foldl { - do all_fields.foldl(base) |&old, &(_, self_f, other_fs)| { + do all_fields.iter().fold(base) |old, &(_, self_f, other_fs)| { f(cx, span, old, self_f, other_fs) } } else { - do all_fields.foldr(base) |&(_, self_f, other_fs), old| { + do all_fields.rev_iter().fold(base) |old, &(_, self_f, other_fs)| { f(cx, span, old, self_f, other_fs) } } @@ -1094,11 +1094,11 @@ pub fn cs_same_method_fold(use_foldl: bool, cs_same_method( |cx, span, vals| { if use_foldl { - do vals.foldl(base) |&old, &new| { + do vals.iter().fold(base) |old, &new| { f(cx, span, old, new) } } else { - do vals.foldr(base) |&new, old| { + do vals.rev_iter().fold(base) |old, &new| { f(cx, span, old, new) } } diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 1107f21319c..c091ab8b617 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -19,6 +19,7 @@ library. */ use core::prelude::*; +use core::iterator::IteratorUtil; use ast::{enum_def, ident, item, Generics, meta_item, struct_def}; use ext::base::ExtCtxt; @@ -74,7 +75,7 @@ pub fn expand_meta_deriving(cx: @ExtCtxt, in_items } meta_list(_, ref titems) => { - do titems.foldr(in_items) |&titem, in_items| { + do titems.rev_iter().fold(in_items) |in_items, &titem| { match titem.node { meta_name_value(tname, _) | meta_list(tname, _) | diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 684d2ac5009..dee18c8a1b3 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -363,7 +363,7 @@ fn validate(edges: ~[(node_id, node_id)], info!(~"Verifying tree edges..."); - let status = do tree.alli() |k, parent| { + let status = do tree.iter().enumerate().all |(k, parent)| { if *parent != root && *parent != -1i64 { level[*parent] == level[k] - 1 } diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index 47cf9177ac2..ee96cc293eb 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -14,7 +14,7 @@ fn main() { let needlesArr: ~[char] = ~['a', 'f']; do needlesArr.iter().fold() |x, y| { } - //~^ ERROR 1 parameter were supplied (including the closure passed by the `do` keyword) + //~^ ERROR 1 parameter was supplied (including the closure passed by the `do` keyword) // // the first error is, um, non-ideal. } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs index 6a90dafa2f1..522516351d2 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; +use std::iterator::IteratorUtil; pub fn main() { let v = ~[-1f, 0f, 1f, 2f, 3f]; diff --git a/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs b/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs index 3dc282fdffa..c6d66e07444 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-block-arg.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; +use std::iterator::IteratorUtil; pub fn main() { fn f(i: &fn() -> uint) -> uint { i() } diff --git a/src/test/run-pass/block-arg-can-be-followed-by-call.rs b/src/test/run-pass/block-arg-can-be-followed-by-call.rs index 0c78735a070..a205e9f8f31 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-call.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-call.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; +use std::iterator::IteratorUtil; pub fn main() { fn f(i: uint) -> uint { i }