diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 4da88981a63575e64db211f29b861e7138803d6f..346e2162385ce56ea75a96aae2357ac462bf057c 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -456,7 +456,7 @@ pub fn ctor_arity(cx: @MatchCheckCtxt, ctor: &ctor, ty: ty::t) -> uint { ty::ty_enum(eid, _) => { let id = match *ctor { variant(id) => id, _ => fail!("impossible case") }; - match vec::find(*ty::enum_variants(cx.tcx, eid), |v| v.id == id ) { + match ty::enum_variants(cx.tcx, eid).iter().find_(|v| v.id == id ) { Some(v) => v.args.len(), None => fail!("impossible case") } diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 368ad0674e1efbfa1901103c76fd10d4f3b23ea9..f082150e39490095770d7a548a27fa9b056448c9 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -209,7 +209,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext, } ast_map::node_variant(ref v, enum_item, _) => { let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id)); - let this_tv = vec::find(*tvs, |tv| { tv.id.node == fn_id.node}).get(); + let this_tv = *tvs.iter().find_(|tv| { tv.id.node == fn_id.node}).get(); let d = mk_lldecl(); set_inline_hint(d); match v.node.kind { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 2340ffc76b3884d2a480379fb03437ad930498d4..8595adcd1c73344dcae184ea18e6dad4d2013d49 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4128,9 +4128,10 @@ pub fn lookup_struct_field(cx: ctxt, parent: ast::def_id, field_id: ast::def_id) -> field_ty { - match vec::find(lookup_struct_fields(cx, parent), + let r = lookup_struct_fields(cx, parent); + match r.iter().find_( |f| f.id.node == field_id.node) { - Some(t) => t, + Some(t) => *t, None => cx.sess.bug("struct ID not found in parent's fields") } } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 2d8233f8c0aad27ea717371745886aa6aeae2e3e..13ded50167939dbb132fb97b513e952469476c04 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1107,7 +1107,7 @@ pub fn lookup_field_ty(tcx: ty::ctxt, fieldname: ast::ident, substs: &ty::substs) -> Option { - let o_field = vec::find(items, |f| f.ident == fieldname); + let o_field = items.iter().find_(|f| f.ident == fieldname); do o_field.map() |f| { ty::lookup_field_type(tcx, class_id, f.id, substs) } diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index a1dad7d17f8e8d2b9afe7b2c7a2c372c136a6d3d..1c34007c99d42f3dd3b441cd97ecdf745da95951 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -135,7 +135,7 @@ fn fold_enum( node: ast::item_enum(ref enum_definition, _), _ }, _) => { let ast_variant = - vec::find(enum_definition.variants, |v| { + copy *enum_definition.variants.iter().find_(|v| { to_str(v.node.name) == variant.name }).get(); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index ef65cc8e5a1b88483b8b78204e2907aa942bf1dd..84a194627fb56fe969f15d106e5c6e50029130c9 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -230,16 +230,15 @@ pub fn maybe_find_pandoc( } }; - let pandoc = do vec::find(possible_pandocs) |pandoc| { + let pandoc = do possible_pandocs.iter().find_ |&pandoc| { let output = process_output(*pandoc, [~"--version"]); debug!("testing pandoc cmd %s: %?", *pandoc, output); output.status == 0 }; - if pandoc.is_some() { - result::Ok(pandoc) - } else { - result::Err(~"couldn't find pandoc") + match pandoc { + Some(x) => Ok(Some(copy *x)), // ugly, shouldn't be doubly wrapped + None => Err(~"couldn't find pandoc") } } diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index 82336addb62fc6ef0d3fb0814712e73fe60f9f9b..e3abe6e926a5ef2145314514c2f14a63605ddb63 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -124,7 +124,7 @@ fn fold_enum( node: ast::item_enum(ref enum_definition, _), _ }, _) => { let ast_variant = - do vec::find(enum_definition.variants) |v| { + copy *do enum_definition.variants.iter().find_ |v| { to_str(v.node.name) == variant.name }.get(); @@ -178,14 +178,14 @@ fn get_method_sig( ast_map::node_item(@ast::item { node: ast::item_trait(_, _, ref methods), _ }, _) => { - match vec::find(*methods, |method| { + match methods.iter().find_(|&method| { match copy *method { ast::required(ty_m) => to_str(ty_m.ident) == method_name, ast::provided(m) => to_str(m.ident) == method_name, } }) { Some(method) => { - match method { + match copy *method { ast::required(ty_m) => { Some(pprust::fun_to_str( &ty_m.decl, @@ -214,7 +214,7 @@ fn get_method_sig( ast_map::node_item(@ast::item { node: ast::item_impl(_, _, _, ref methods), _ }, _) => { - match vec::find(*methods, |method| { + match methods.iter().find_(|method| { to_str(method.ident) == method_name }) { Some(method) => { diff --git a/src/libstd/str.rs b/src/libstd/str.rs index fd11b49a00a310afa57f5ee088f8a7e83bec2ba0..f3226b27d1be35326e37f51636539bf4e9d22885 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -60,7 +60,7 @@ pub fn from_bytes(vv: &[u8]) -> ~str { use str::not_utf8::cond; if !is_utf8(vv) { - let first_bad_byte = vec::find(vv, |b| !is_utf8([*b])).get(); + let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).get(); cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", first_bad_byte as uint)) } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index ce5662c6d4b3997d3b5784ffc7f77d673e7872b9..703224e37c579546569e96d99c19ae2b9d94cbe5 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1056,17 +1056,6 @@ pub fn contains(v: &[T], x: &T) -> bool { false } -/** - * Search for the first element that matches a given predicate - * - * Apply function `f` to each element of `v`, starting from the first. - * When function `f` returns true then an option containing the element - * is returned. If `f` matches no elements then none is returned. - */ -pub fn find(v: &[T], f: &fn(t: &T) -> bool) -> Option { - find_between(v, 0u, v.len(), f) -} - /** * Search for the first element that matches a given predicate within a range * @@ -3163,18 +3152,6 @@ fn test_position_between() { assert!(position_between(v, 4u, 4u, f).is_none()); } - #[test] - fn test_find() { - assert!(find([], f).is_none()); - - fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } - fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } - let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; - - assert_eq!(find(v, f), Some((1, 'b'))); - assert!(find(v, g).is_none()); - } - #[test] fn test_find_between() { assert!(find_between([], 0u, 0u, f).is_none()); @@ -3205,8 +3182,6 @@ fn test_find_between() { #[test] fn test_rposition() { - assert!(find([], f).is_none()); - fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; @@ -3838,22 +3813,6 @@ fn test_filter_fail() { }; } - #[test] - #[ignore(windows)] - #[should_fail] - #[allow(non_implicitly_copyable_typarams)] - fn test_find_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do find(v) |_elt| { - if i == 2 { - fail!() - } - i += 0; - false - }; - } - #[test] #[ignore(windows)] #[should_fail]