From 65c7c58c8f15189d2e4ca6b166e933c5fe2d0691 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 8 Jun 2013 14:07:55 +1000 Subject: [PATCH] std: remove {all*,any*,count} in favour of iterators --- src/libextra/par.rs | 18 +- src/librustc/middle/trans/_match.rs | 17 +- src/librustc/middle/trans/monomorphize.rs | 3 +- src/librustc/middle/ty.rs | 20 ++- src/librustc/middle/typeck/check/mod.rs | 2 +- src/libstd/iterator.rs | 20 +-- src/libstd/str.rs | 27 +-- src/libstd/vec.rs | 174 +------------------ src/test/bench/graph500-bfs.rs | 5 +- src/test/run-pass/block-arg.rs | 17 +- src/test/run-pass/ret-break-cont-in-block.rs | 4 +- src/test/run-pass/test-ignore-cfg.rs | 12 +- 12 files changed, 78 insertions(+), 241 deletions(-) diff --git a/src/libextra/par.rs b/src/libextra/par.rs index 49696a5fa25..23b7cdc0997 100644 --- a/src/libextra/par.rs +++ b/src/libextra/par.rs @@ -10,6 +10,7 @@ use core::prelude::*; +use core::iterator::IteratorUtil; use core::cast; use core::ptr; use core::sys; @@ -122,25 +123,24 @@ pub fn alli( xs: &[A], fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool { - do vec::all(map_slices(xs, || { + let mapped = map_slices(xs, || { let f = fn_factory(); let result: ~fn(uint, &[A]) -> bool = |base, slice| { - vec::alli(slice, |i, x| { - f(i + base, x) - }) + slice.iter().enumerate().all(|(i, x)| f(i + base, x)) }; result - })) |x| { *x } + }); + mapped.iter().all(|&x| x) } /// Returns true if the function holds for any elements in the vector. pub fn any( xs: &[A], fn_factory: &fn() -> ~fn(&A) -> bool) -> bool { - do vec::any(map_slices(xs, || { + let mapped = map_slices(xs, || { let f = fn_factory(); - let result: ~fn(uint, &[A]) -> bool = - |_, slice| vec::any(slice, |x| f(x)); + let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any(f); result - })) |x| { *x } + }); + mapped.iter().any(|&x| x) } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index a42e1cd0647..49db0ee7bd3 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -172,6 +172,7 @@ use middle::trans::type_of; use middle::ty; use util::common::indenter; +use core::iterator::IteratorUtil; use core::hashmap::HashMap; use core::vec; use syntax::ast; @@ -798,7 +799,7 @@ pub fn enter_region<'r>(bcx: block, pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] { let ccx = bcx.ccx(); fn add_to_set(tcx: ty::ctxt, set: &mut ~[Opt], val: Opt) { - if set.any(|l| opt_eq(tcx, l, &val)) {return;} + if set.iter().any(|l| opt_eq(tcx, l, &val)) {return;} set.push(val); } @@ -965,7 +966,7 @@ pub fn collect_record_or_struct_fields(bcx: block, fn extend(idents: &mut ~[ast::ident], field_pats: &[ast::field_pat]) { for field_pats.each |field_pat| { let field_ident = field_pat.ident; - if !vec::any(*idents, |x| *x == field_ident) { + if !idents.iter().any(|x| *x == field_ident) { idents.push(field_ident); } } @@ -976,11 +977,11 @@ pub fn pats_require_rooting(bcx: block, m: &[@Match], col: uint) -> bool { - vec::any(m, |br| { + do m.iter().any |br| { let pat_id = br.pats[col].id; let key = root_map_key {id: pat_id, derefs: 0u }; bcx.ccx().maps.root_map.contains_key(&key) - }) + } } pub fn root_pats_as_necessary(mut bcx: block, @@ -1005,12 +1006,12 @@ pub fn root_pats_as_necessary(mut bcx: block, // matches may be wildcards like _ or identifiers). macro_rules! any_pat ( ($m:expr, $pattern:pat) => ( - vec::any($m, |br| { + do ($m).iter().any |br| { match br.pats[col].node { $pattern => true, _ => false } - }) + } ) ) @@ -1031,7 +1032,7 @@ pub fn any_tup_pat(m: &[@Match], col: uint) -> bool { } pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool { - vec::any(m, |br| { + do m.iter().any |br| { let pat = br.pats[col]; match pat.node { ast::pat_enum(_, Some(_)) => { @@ -1043,7 +1044,7 @@ pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool { } _ => false } - }) + } } pub type mk_fail = @fn() -> BasicBlockRef; diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 062f72b6feb..169cd294b43 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -32,6 +32,7 @@ use middle::ty::{FnSig}; use middle::typeck; use util::ppaux::{Repr,ty_to_str}; +use core::iterator::IteratorUtil; use core::vec; use syntax::ast; use syntax::ast_map; @@ -75,7 +76,7 @@ pub fn monomorphic_fn(ccx: @CrateContext, let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len()); let hash_id = make_mono_id(ccx, fn_id, substs, vtables, impl_did_opt, Some(param_uses)); - if vec::any(hash_id.params, + if hash_id.params.iter().any( |p| match *p { mono_precise(_, _) => false, _ => true }) { must_cast = true; } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 8e2691c8a27..e8501904c6f 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -27,6 +27,7 @@ use util::ppaux::{Repr, UserString}; use util::common::{indenter}; use util::enum_set::{EnumSet, CLike}; +use core::iterator::IteratorUtil; use core::cast; use core::cmp; use core::hashmap::{HashMap, HashSet}; @@ -2355,8 +2356,8 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { ty_struct(did, ref substs) => { seen.push(did); - let r = vec::any(struct_fields(cx, did, substs), - |f| type_requires(cx, seen, r_ty, f.mt.ty)); + let fields = struct_fields(cx, did, substs); + let r = fields.iter().any(|f| type_requires(cx, seen, r_ty, f.mt.ty)); seen.pop(); r } @@ -2372,12 +2373,12 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { ty_enum(did, ref substs) => { seen.push(did); let vs = enum_variants(cx, did); - let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| { - vec::any(variant.args, |aty| { + let r = vec::len(*vs) > 0u && do vs.iter().all |variant| { + do variant.args.iter().any |aty| { let sty = subst(cx, substs, *aty); type_requires(cx, seen, r_ty, sty) - }) - }); + } + }; seen.pop(); r } @@ -2519,11 +2520,12 @@ pub fn type_is_pod(cx: ctxt, ty: t) -> bool { ty_param(_) => result = false, ty_opaque_closure_ptr(_) => result = true, ty_struct(did, ref substs) => { - result = vec::all(lookup_struct_fields(cx, did), |f| { + let fields = lookup_struct_fields(cx, did); + result = do fields.iter().all |f| { let fty = ty::lookup_item_type(cx, f.id); let sty = subst(cx, substs, fty.ty); type_is_pod(cx, sty) - }); + }; } ty_estr(vstore_slice(*)) | ty_evec(_, vstore_slice(*)) => { @@ -2569,7 +2571,7 @@ pub fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool { if variants.len() == 0 { false } else { - variants.all(|v| v.args.len() == 0) + variants.iter().all(|v| v.args.len() == 0) } } _ => false diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 9241fb6da90..9eb5f815954 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3065,7 +3065,7 @@ pub fn check_simd(tcx: ty::ctxt, sp: span, id: ast::node_id) { return; } let e = ty::lookup_field_type(tcx, did, fields[0].id, substs); - if !vec::all(fields, + if !fields.iter().all( |f| ty::lookup_field_type(tcx, did, f.id, substs) == e) { tcx.sess.span_err(sp, "SIMD vector should be homogeneous"); return; diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 4ed82f63b39..309e207eaaa 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -326,7 +326,7 @@ pub trait IteratorUtil { /// assert!(a.iter().all(|&x| *x > 0)); /// assert!(!a.iter().all(|&x| *x > 2)); /// ~~~ - fn all(&mut self, f: &fn(&A) -> bool) -> bool; + fn all(&mut self, f: &fn(A) -> bool) -> bool; /// Tests whether any element of an iterator satisfies the specified /// predicate. @@ -341,7 +341,7 @@ pub trait IteratorUtil { /// assert!(it.any(|&x| *x == 3)); /// assert!(!it.any(|&x| *x == 3)); /// ~~~ - fn any(&mut self, f: &fn(&A) -> bool) -> bool; + fn any(&mut self, f: &fn(A) -> bool) -> bool; } /// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also @@ -462,14 +462,14 @@ impl> IteratorUtil for T { fn count(&mut self) -> uint { self.fold(0, |cnt, _x| cnt + 1) } #[inline(always)] - fn all(&mut self, f: &fn(&A) -> bool) -> bool { - for self.advance |x| { if !f(&x) { return false; } } + fn all(&mut self, f: &fn(A) -> bool) -> bool { + for self.advance |x| { if !f(x) { return false; } } return true; } #[inline(always)] - fn any(&mut self, f: &fn(&A) -> bool) -> bool { - for self.advance |x| { if f(&x) { return true; } } + fn any(&mut self, f: &fn(A) -> bool) -> bool { + for self.advance |x| { if f(x) { return true; } } return false; } } @@ -1080,18 +1080,18 @@ mod tests { #[test] fn test_all() { let v = ~&[1, 2, 3, 4, 5]; - assert!(v.iter().all(|&x| *x < 10)); + assert!(v.iter().all(|&x| x < 10)); assert!(!v.iter().all(|&x| x.is_even())); - assert!(!v.iter().all(|&x| *x > 100)); + assert!(!v.iter().all(|&x| x > 100)); assert!(v.slice(0, 0).iter().all(|_| fail!())); } #[test] fn test_any() { let v = ~&[1, 2, 3, 4, 5]; - assert!(v.iter().any(|&x| *x < 10)); + assert!(v.iter().any(|&x| x < 10)); assert!(v.iter().any(|&x| x.is_even())); - assert!(!v.iter().any(|&x| *x > 100)); + assert!(!v.iter().any(|&x| x > 100)); assert!(!v.slice(0, 0).iter().any(|_| fail!())); } } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 8dc546ec4f8..d0345a3953e 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -2883,6 +2883,7 @@ impl<'self> Iterator for StrCharIterator<'self> { #[cfg(test)] mod tests { + use iterator::IteratorUtil; use container::Container; use char; use option::Some; @@ -2977,7 +2978,7 @@ mod tests { let mut v = ~[]; for each_split_char(s, c) |s| { v.push(s.to_owned()) } debug!("split_byte to: %?", v); - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("abc.hello.there", '.', [~"abc", ~"hello", ~"there"]); t(".hello.there", '.', [~"", ~"hello", ~"there"]); @@ -2995,7 +2996,7 @@ mod tests { let mut v = ~[]; for each_split_char(s, c) |s| { v.push(s.to_owned()) } debug!("split_byte to: %?", v); - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } let data = "ประเทศไทย中华Việt Nam"; t(data, 'V', [~"ประเทศไทย中华", ~"iệt Nam"]); @@ -3010,7 +3011,7 @@ mod tests { for each_splitn_char(s, c, n) |s| { v.push(s.to_owned()) } debug!("split_byte to: %?", v); debug!("comparing vs. %?", u); - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("abc.hello.there", '.', 0u, [~"abc.hello.there"]); t("abc.hello.there", '.', 1u, [~"abc", ~"hello.there"]); @@ -3037,7 +3038,7 @@ mod tests { for each_splitn_char(s, c, n) |s| { v.push(s.to_owned()) } debug!("split_byte to: %?", v); debug!("comparing vs. %?", u); - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("ประเทศไทย中华Việt Nam", '华', 1u, [~"ประเทศไทย中", ~"Việt Nam"]); @@ -3055,7 +3056,7 @@ mod tests { for each_splitn_char(s, c, n) |s| { v.push(s.to_owned()) } debug!("split_byte to: %?", v); debug!("comparing vs. %?", u); - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } let data = "ประเทศไทย中华Việt Nam"; t(data, 'V', 1u, [~"ประเทศไทย中华", ~"iệt Nam"]); @@ -3069,7 +3070,7 @@ mod tests { let mut v = ~[]; for each_split_char_no_trailing(s, c) |s| { v.push(s.to_owned()) } debug!("split_byte to: %?", v); - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("abc.hello.there", '.', [~"abc", ~"hello", ~"there"]); t(".hello.there", '.', [~"", ~"hello", ~"there"]); @@ -3088,7 +3089,7 @@ mod tests { let mut v = ~[]; for each_split_char_no_trailing(s, c) |s| { v.push(s.to_owned()) } debug!("split_byte to: %?", v); - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } let data = "ประเทศไทย中华Việt Nam"; t(data, 'V', [~"ประเทศไทย中华", ~"iệt Nam"]); @@ -3100,7 +3101,7 @@ mod tests { fn t<'a>(s: &str, sep: &'a str, u: &[~str]) { let mut v = ~[]; for each_split_str(s, sep) |s| { v.push(s.to_owned()) } - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("--1233345--", "12345", [~"--1233345--"]); t("abc::hello::there", "::", [~"abc", ~"hello", ~"there"]); @@ -3124,7 +3125,7 @@ mod tests { fn t(s: &str, sepf: &fn(char) -> bool, u: &[~str]) { let mut v = ~[]; for each_split(s, sepf) |s| { v.push(s.to_owned()) } - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("ประเทศไทย中华Việt Nam", |cc| cc == '华', [~"ประเทศไทย中", ~"Việt Nam"]); @@ -3140,7 +3141,7 @@ mod tests { fn t(s: &str, sepf: &fn(char) -> bool, u: &[~str]) { let mut v = ~[]; for each_split_no_trailing(s, sepf) |s| { v.push(s.to_owned()) } - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("ประเทศไทย中华Việt Nam", |cc| cc == '华', [~"ประเทศไทย中", ~"Việt Nam"]); @@ -3159,7 +3160,7 @@ mod tests { fn t(s: &str, f: &fn(&str, &fn(&str) -> bool) -> bool, u: &[~str]) { let mut v = ~[]; for f(s) |s| { v.push(s.to_owned()) } - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t(lf, each_line, [~"", ~"Mary had a little lamb", ~"Little lamb"]); @@ -3179,7 +3180,7 @@ mod tests { fn t(s: &str, f: &fn(&str, &fn(&str) -> bool) -> bool, u: &[~str]) { let mut v = ~[]; for f(s) |s| { v.push(s.to_owned()) } - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } let data = "\nMary had a little lamb\nLittle lamb\n"; @@ -3193,7 +3194,7 @@ mod tests { fn t(s: &str, i: uint, u: &[~str]) { let mut v = ~[]; for each_split_within(s, i) |s| { v.push(s.to_owned()) } - assert!(vec::all2(v, u, |a,b| a == b)); + assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } t("", 0, []); t("", 15, []); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index f34e1a91b69..29f2dba77a6 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1124,80 +1124,12 @@ pub fn foldr<'a, T, U>(v: &'a [T], mut z: U, p: &fn(t: &'a T, u: U) -> U) -> U { return z; } -/** - * Return true if a predicate matches any elements - * - * If the vector contains no elements then false is returned. - */ -pub fn any(v: &[T], f: &fn(t: &T) -> bool) -> bool { - for each(v) |elem| { if f(elem) { return true; } } - false -} - -/** - * Return true if a predicate matches any elements in both vectors. - * - * If the vectors contains no elements then false is returned. - */ -pub fn any2(v0: &[T], v1: &[U], - f: &fn(a: &T, b: &U) -> bool) -> bool { - let v0_len = len(v0); - let v1_len = len(v1); - let mut i = 0u; - while i < v0_len && i < v1_len { - if f(&v0[i], &v1[i]) { return true; }; - i += 1u; - } - false -} - -/** - * Return true if a predicate matches all elements - * - * If the vector contains no elements then true is returned. - */ -pub fn all(v: &[T], f: &fn(t: &T) -> bool) -> bool { - for each(v) |elem| { if !f(elem) { return false; } } - true -} - -/** - * Return true if a predicate matches all elements - * - * If the vector contains no elements then true is returned. - */ -pub fn alli(v: &[T], f: &fn(uint, t: &T) -> bool) -> bool { - for eachi(v) |i, elem| { if !f(i, elem) { return false; } } - true -} - -/** - * Return true if a predicate matches all elements in both vectors. - * - * If the vectors are not the same size then false is returned. - */ -pub fn all2(v0: &[T], v1: &[U], - f: &fn(t: &T, u: &U) -> bool) -> bool { - let v0_len = len(v0); - if v0_len != len(v1) { return false; } - let mut i = 0u; - while i < v0_len { if !f(&v0[i], &v1[i]) { return false; }; i += 1u; } - true -} - /// Return true if a vector contains an element with the given value pub fn contains(v: &[T], x: &T) -> bool { for each(v) |elt| { if *x == *elt { return true; } } false } -/// Returns the number of elements that are equal to a given value -pub fn count(v: &[T], x: &T) -> uint { - let mut cnt = 0u; - for each(v) |elt| { if *x == *elt { cnt += 1u; } } - cnt -} - /** * Search for the first element that matches a given predicate * @@ -2074,7 +2006,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { * If the vector is empty, true is returned. */ fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool { - alli(*self, f) + self.iter().enumerate().all(|(i, t)| f(i,t)) } /** * Apply a function to each element of a vector and return a concatenation @@ -3558,33 +3490,6 @@ mod tests { ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]); } - #[test] - fn test_any_and_all() { - assert!(any([1u, 2u, 3u], is_three)); - assert!(!any([0u, 1u, 2u], is_three)); - assert!(any([1u, 2u, 3u, 4u, 5u], is_three)); - assert!(!any([1u, 2u, 4u, 5u, 6u], is_three)); - - assert!(all([3u, 3u, 3u], is_three)); - assert!(!all([3u, 3u, 2u], is_three)); - assert!(all([3u, 3u, 3u, 3u, 3u], is_three)); - assert!(!all([3u, 3u, 0u, 1u, 2u], is_three)); - } - - #[test] - fn test_any2_and_all2() { - - assert!(any2([2u, 4u, 6u], [2u, 4u, 6u], is_equal)); - assert!(any2([1u, 2u, 3u], [4u, 5u, 3u], is_equal)); - assert!(!any2([1u, 2u, 3u], [4u, 5u, 6u], is_equal)); - assert!(any2([2u, 4u, 6u], [2u, 4u], is_equal)); - - assert!(all2([2u, 4u, 6u], [2u, 4u, 6u], is_equal)); - assert!(!all2([1u, 2u, 3u], [4u, 5u, 3u], is_equal)); - assert!(!all2([1u, 2u, 3u], [4u, 5u, 6u], is_equal)); - assert!(!all2([2u, 4u, 6u], [2u, 4u], is_equal)); - } - #[test] fn test_zip_unzip() { let v1 = ~[1, 2, 3]; @@ -4361,81 +4266,6 @@ mod tests { }; } - #[test] - #[ignore(windows)] - #[should_fail] - fn test_any_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do any(v) |_elt| { - if i == 2 { - fail!() - } - i += 0; - false - }; - } - - #[test] - #[ignore(windows)] - #[should_fail] - fn test_any2_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do any(v) |_elt| { - if i == 2 { - fail!() - } - i += 0; - false - }; - } - - #[test] - #[ignore(windows)] - #[should_fail] - fn test_all_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do all(v) |_elt| { - if i == 2 { - fail!() - } - i += 0; - true - }; - } - - #[test] - #[ignore(windows)] - #[should_fail] - fn test_alli_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do alli(v) |_i, _elt| { - if i == 2 { - fail!() - } - i += 0; - true - }; - } - - #[test] - #[ignore(windows)] - #[should_fail] - fn test_all2_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do all2(v, v) |_elt1, _elt2| { - if i == 2 { - fail!() - } - i += 0; - true - }; - } - #[test] #[ignore(windows)] #[should_fail] @@ -4617,7 +4447,7 @@ mod tests { #[test] fn test_mut_rev_iterator() { use iterator::*; - let mut xs = [1, 2, 3, 4, 5]; + let mut xs = [1u, 2, 3, 4, 5]; for xs.mut_rev_iter().enumerate().advance |(i,x)| { *x += i; } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 38cc3127343..684d2ac5009 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -21,6 +21,7 @@ use extra::arc; use extra::time; use extra::deque::Deque; use extra::par; +use std::iterator::IteratorUtil; use std::hashmap::HashSet; use std::int::abs; use std::io; @@ -111,7 +112,7 @@ fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] { while keys.len() < n { let k = r.gen_uint_range(0u, graph.len()); - if graph[k].len() > 0u && vec::any(graph[k], |i| { + if graph[k].len() > 0u && graph[k].iter().any(|i| { *i != k as node_id }) { keys.insert(k as node_id); @@ -187,7 +188,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { } let mut i = 0; - while vec::any(colors, is_gray) { + while colors.iter().any(is_gray) { // Do the BFS. info!("PBFS iteration %?", i); i += 1; diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index 906a3629f3a..ae6e04b3018 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::iterator::IteratorUtil; use std::vec; // Check usage and precedence of block arguments in expressions: @@ -20,28 +21,28 @@ pub fn main() { } // Usable at all: - let mut any_negative = do vec::any(v) |e| { e.is_negative() }; + let mut any_negative = do v.iter().any |e| { e.is_negative() }; assert!(any_negative); // Higher precedence than assignments: - any_negative = do vec::any(v) |e| { e.is_negative() }; + any_negative = do v.iter().any |e| { e.is_negative() }; assert!(any_negative); // Higher precedence than unary operations: let abs_v = do vec::map(v) |e| { e.abs() }; - assert!(do vec::all(abs_v) |e| { e.is_positive() }); - assert!(!do vec::any(abs_v) |e| { e.is_negative() }); + assert!(do abs_v.iter().all |e| { e.is_positive() }); + assert!(!do abs_v.iter().any |e| { e.is_negative() }); // Usable in funny statement-like forms: - if !do vec::any(v) |e| { e.is_positive() } { + if !do v.iter().any |e| { e.is_positive() } { assert!(false); } - match do vec::all(v) |e| { e.is_negative() } { + match do v.iter().all |e| { e.is_negative() } { true => { fail!("incorrect answer."); } false => { } } match 3 { - _ if do vec::any(v) |e| { e.is_negative() } => { + _ if do v.iter().any |e| { e.is_negative() } => { } _ => { fail!("wrong answer."); @@ -58,7 +59,7 @@ pub fn main() { // In the tail of a block let w = - if true { do vec::any(abs_v) |e| { e.is_positive() } } + if true { do abs_v.iter().any |e| { e.is_positive() } } else { false }; assert!(w); } diff --git a/src/test/run-pass/ret-break-cont-in-block.rs b/src/test/run-pass/ret-break-cont-in-block.rs index 80e6293bf50..4346d242c06 100644 --- a/src/test/run-pass/ret-break-cont-in-block.rs +++ b/src/test/run-pass/ret-break-cont-in-block.rs @@ -10,6 +10,7 @@ // xfail-fast +use std::iterator::IteratorUtil; use std::cmp::Eq; use std::vec; @@ -54,7 +55,8 @@ fn ret_deep() -> ~str { pub fn main() { let mut last = 0; - for vec::all(~[1, 2, 3, 4, 5, 6, 7]) |e| { + let v = ~[1, 2, 3, 4, 5, 6, 7]; + for v.iter().all |e| { last = *e; if *e == 5 { break; } if *e % 2 == 1 { loop; } diff --git a/src/test/run-pass/test-ignore-cfg.rs b/src/test/run-pass/test-ignore-cfg.rs index d8b12437dfa..cbfaa87b699 100644 --- a/src/test/run-pass/test-ignore-cfg.rs +++ b/src/test/run-pass/test-ignore-cfg.rs @@ -13,7 +13,7 @@ extern mod extra; -use std::vec; +use std::iterator::IteratorUtil; #[test] #[ignore(cfg(ignorecfg))] @@ -30,11 +30,9 @@ fn checktests() { // Pull the tests out of the secreturn test module let tests = __test::tests; - assert!(vec::any( - tests, - |t| t.desc.name.to_str() == ~"shouldignore" && t.desc.ignore)); + assert!( + tests.iter().any(|t| t.desc.name.to_str() == ~"shouldignore" && t.desc.ignore)); - assert!(vec::any( - tests, - |t| t.desc.name.to_str() == ~"shouldnotignore" && !t.desc.ignore)); + assert!( + tests.iter().any(|t| t.desc.name.to_str() == ~"shouldnotignore" && !t.desc.ignore)); }