replace vec::find with the IteratorUtil method
This commit is contained in:
parent
883c966d5c
commit
06bec77faf
9 changed files with 16 additions and 57 deletions
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1107,7 +1107,7 @@ pub fn lookup_field_ty(tcx: ty::ctxt,
|
|||
fieldname: ast::ident,
|
||||
substs: &ty::substs) -> Option<ty::t> {
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1056,17 +1056,6 @@ pub fn contains<T:Eq>(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<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
|
||||
find_between(v, 0u, v.len(), f)
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for the first element that matches a given predicate within a range
|
||||
*
|
||||
|
|
@ -3163,18 +3152,6 @@ mod tests {
|
|||
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 @@ mod tests {
|
|||
|
||||
#[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 @@ mod tests {
|
|||
};
|
||||
}
|
||||
|
||||
#[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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue