diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index 05649104c31..5980bd7c9e4 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -177,7 +177,7 @@ fn name_str(nm: &Name) -> ~str { } fn find_opt(opts: &[Opt], nm: Name) -> Option { - vec::position(opts, |opt| opt.name == nm) + opts.iter().position_(|opt| opt.name == nm) } /** diff --git a/src/libextra/json.rs b/src/libextra/json.rs index db95327f0aa..0bbccd4df4a 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -950,7 +950,7 @@ impl serialize::Decoder for Decoder { } ref json => fail!("invalid variant: %?", *json), }; - let idx = match vec::position(names, |n| str::eq_slice(*n, name)) { + let idx = match names.iter().position_(|n| str::eq_slice(*n, name)) { Some(idx) => idx, None => fail!("Unknown variant name: %?", name), }; diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index fc79c8c23d4..e9a0d42f29b 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -468,8 +468,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) { pub fn revoke_clean(cx: block, val: ValueRef) { do in_scope_cx(cx) |scope_info| { let scope_info = &mut *scope_info; // FIXME(#5074) workaround borrowck - let cleanup_pos = vec::position( - scope_info.cleanups, + let cleanup_pos = scope_info.cleanups.iter().position_( |cu| match *cu { clean_temp(v, _, _) if v == val => true, _ => false diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 3cbbd61aed6..d1467edd94d 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1152,8 +1152,7 @@ fn trans_rec_or_struct(bcx: block, let mut need_base = vec::from_elem(field_tys.len(), true); let numbered_fields = do fields.map |field| { - let opt_pos = vec::position(field_tys, |field_ty| - field_ty.ident == field.node.ident); + let opt_pos = field_tys.iter().position_(|field_ty| field_ty.ident == field.node.ident); match opt_pos { Some(i) => { need_base[i] = false; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index a4702808746..2340ffc76b3 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3372,7 +3372,7 @@ pub fn field_idx_strict(tcx: ty::ctxt, id: ast::ident, fields: &[field]) } pub fn method_idx(id: ast::ident, meths: &[@Method]) -> Option { - vec::position(meths, |m| m.ident == id) + meths.iter().position_(|m| m.ident == id) } /// Returns a vector containing the indices of all type parameters that appear diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index bdf88cb6df4..2b7f7d0f77c 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -420,7 +420,7 @@ impl<'self> LookupContext<'self> { let tcx = self.tcx(); let ms = ty::trait_methods(tcx, did); - let index = match vec::position(*ms, |m| m.ident == self.m_name) { + let index = match ms.iter().position_(|m| m.ident == self.m_name) { Some(i) => i, None => { return; } // no method with the right name }; @@ -474,7 +474,7 @@ impl<'self> LookupContext<'self> { // First, try self methods let mut method_info: Option = None; let methods = ty::trait_methods(tcx, did); - match vec::position(*methods, |m| m.ident == self.m_name) { + match methods.iter().position_(|m| m.ident == self.m_name) { Some(i) => { method_info = Some(MethodInfo { method_ty: methods[i], @@ -489,8 +489,7 @@ impl<'self> LookupContext<'self> { for ty::trait_supertraits(tcx, did).each() |trait_ref| { let supertrait_methods = ty::trait_methods(tcx, trait_ref.def_id); - match vec::position(*supertrait_methods, - |m| m.ident == self.m_name) { + match supertrait_methods.iter().position_(|m| m.ident == self.m_name) { Some(i) => { method_info = Some(MethodInfo { method_ty: supertrait_methods[i], diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 57f23d8e657..394066f1d4c 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -22,7 +22,7 @@ use iter::{FromIter, Times}; use num::{Zero, One}; use option::{Option, Some, None}; use ops::{Add, Mul}; -use cmp::{Ord, Eq}; +use cmp::Ord; use clone::Clone; /// An interface for dealing with "external iterators". These types of iterators diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index ad03d8fc4a0..ce5662c6d4b 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -19,7 +19,7 @@ use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater}; use clone::Clone; use old_iter::BaseIter; use old_iter; -use iterator::{Iterator}; +use iterator::{Iterator, IteratorUtil}; use iter::FromIter; use kinds::Copy; use libc; @@ -1107,18 +1107,7 @@ pub fn rfind_between(v: &[T], /// Find the first index containing a matching value pub fn position_elem(v: &[T], x: &T) -> Option { - position(v, |y| *x == *y) -} - -/** - * Find the first index matching some predicate - * - * Apply function `f` to each element of `v`. When function `f` returns true - * then an option containing the index is returned. If `f` matches no elements - * then none is returned. - */ -pub fn position(v: &[T], f: &fn(t: &T) -> bool) -> Option { - position_between(v, 0u, v.len(), f) + v.iter().position_(|y| *x == *y) } /** @@ -3146,18 +3135,6 @@ mod tests { assert!(position_elem(v1, &4).is_none()); } - #[test] - fn test_position() { - fn less_than_three(i: &int) -> bool { *i < 3 } - fn is_eighteen(i: &int) -> bool { *i == 18 } - - assert!(position([], less_than_three).is_none()); - - let v1 = ~[5, 4, 3, 2, 1]; - assert_eq!(position(v1, less_than_three), Some(3u)); - assert!(position(v1, is_eighteen).is_none()); - } - #[test] fn test_position_between() { assert!(position_between([], 0u, 0u, f).is_none()); @@ -3234,8 +3211,8 @@ mod tests { fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; - assert_eq!(position(v, f), Some(1u)); - assert!(position(v, g).is_none()); + assert_eq!(rposition(v, f), Some(3u)); + assert!(rposition(v, g).is_none()); } #[test] @@ -3877,21 +3854,6 @@ mod tests { }; } - #[test] - #[ignore(windows)] - #[should_fail] - fn test_position_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do position(v) |_elt| { - if i == 2 { - fail!() - } - i += 0; - false - }; - } - #[test] #[ignore(windows)] #[should_fail]