Skip to content

Commit 06bec77

Browse files
committed
replace vec::find with the IteratorUtil method
1 parent 883c966 commit 06bec77

File tree

9 files changed

+16
-57
lines changed

9 files changed

+16
-57
lines changed

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ pub fn ctor_arity(cx: @MatchCheckCtxt, ctor: &ctor, ty: ty::t) -> uint {
456456
ty::ty_enum(eid, _) => {
457457
let id = match *ctor { variant(id) => id,
458458
_ => fail!("impossible case") };
459-
match vec::find(*ty::enum_variants(cx.tcx, eid), |v| v.id == id ) {
459+
match ty::enum_variants(cx.tcx, eid).iter().find_(|v| v.id == id ) {
460460
Some(v) => v.args.len(),
461461
None => fail!("impossible case")
462462
}

src/librustc/middle/trans/monomorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
209209
}
210210
ast_map::node_variant(ref v, enum_item, _) => {
211211
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
212-
let this_tv = vec::find(*tvs, |tv| { tv.id.node == fn_id.node}).get();
212+
let this_tv = *tvs.iter().find_(|tv| { tv.id.node == fn_id.node}).get();
213213
let d = mk_lldecl();
214214
set_inline_hint(d);
215215
match v.node.kind {

src/librustc/middle/ty.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4128,9 +4128,10 @@ pub fn lookup_struct_field(cx: ctxt,
41284128
parent: ast::def_id,
41294129
field_id: ast::def_id)
41304130
-> field_ty {
4131-
match vec::find(lookup_struct_fields(cx, parent),
4131+
let r = lookup_struct_fields(cx, parent);
4132+
match r.iter().find_(
41324133
|f| f.id.node == field_id.node) {
4133-
Some(t) => t,
4134+
Some(t) => *t,
41344135
None => cx.sess.bug("struct ID not found in parent's fields")
41354136
}
41364137
}

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ pub fn lookup_field_ty(tcx: ty::ctxt,
11071107
fieldname: ast::ident,
11081108
substs: &ty::substs) -> Option<ty::t> {
11091109

1110-
let o_field = vec::find(items, |f| f.ident == fieldname);
1110+
let o_field = items.iter().find_(|f| f.ident == fieldname);
11111111
do o_field.map() |f| {
11121112
ty::lookup_field_type(tcx, class_id, f.id, substs)
11131113
}

src/librustdoc/attr_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn fold_enum(
135135
node: ast::item_enum(ref enum_definition, _), _
136136
}, _) => {
137137
let ast_variant =
138-
vec::find(enum_definition.variants, |v| {
138+
copy *enum_definition.variants.iter().find_(|v| {
139139
to_str(v.node.name) == variant.name
140140
}).get();
141141

src/librustdoc/config.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,15 @@ pub fn maybe_find_pandoc(
230230
}
231231
};
232232

233-
let pandoc = do vec::find(possible_pandocs) |pandoc| {
233+
let pandoc = do possible_pandocs.iter().find_ |&pandoc| {
234234
let output = process_output(*pandoc, [~"--version"]);
235235
debug!("testing pandoc cmd %s: %?", *pandoc, output);
236236
output.status == 0
237237
};
238238

239-
if pandoc.is_some() {
240-
result::Ok(pandoc)
241-
} else {
242-
result::Err(~"couldn't find pandoc")
239+
match pandoc {
240+
Some(x) => Ok(Some(copy *x)), // ugly, shouldn't be doubly wrapped
241+
None => Err(~"couldn't find pandoc")
243242
}
244243
}
245244

src/librustdoc/tystr_pass.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn fold_enum(
124124
node: ast::item_enum(ref enum_definition, _), _
125125
}, _) => {
126126
let ast_variant =
127-
do vec::find(enum_definition.variants) |v| {
127+
copy *do enum_definition.variants.iter().find_ |v| {
128128
to_str(v.node.name) == variant.name
129129
}.get();
130130

@@ -178,14 +178,14 @@ fn get_method_sig(
178178
ast_map::node_item(@ast::item {
179179
node: ast::item_trait(_, _, ref methods), _
180180
}, _) => {
181-
match vec::find(*methods, |method| {
181+
match methods.iter().find_(|&method| {
182182
match copy *method {
183183
ast::required(ty_m) => to_str(ty_m.ident) == method_name,
184184
ast::provided(m) => to_str(m.ident) == method_name,
185185
}
186186
}) {
187187
Some(method) => {
188-
match method {
188+
match copy *method {
189189
ast::required(ty_m) => {
190190
Some(pprust::fun_to_str(
191191
&ty_m.decl,
@@ -214,7 +214,7 @@ fn get_method_sig(
214214
ast_map::node_item(@ast::item {
215215
node: ast::item_impl(_, _, _, ref methods), _
216216
}, _) => {
217-
match vec::find(*methods, |method| {
217+
match methods.iter().find_(|method| {
218218
to_str(method.ident) == method_name
219219
}) {
220220
Some(method) => {

src/libstd/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn from_bytes(vv: &[u8]) -> ~str {
6060
use str::not_utf8::cond;
6161

6262
if !is_utf8(vv) {
63-
let first_bad_byte = vec::find(vv, |b| !is_utf8([*b])).get();
63+
let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).get();
6464
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
6565
first_bad_byte as uint))
6666
}

src/libstd/vec.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,17 +1056,6 @@ pub fn contains<T:Eq>(v: &[T], x: &T) -> bool {
10561056
false
10571057
}
10581058

1059-
/**
1060-
* Search for the first element that matches a given predicate
1061-
*
1062-
* Apply function `f` to each element of `v`, starting from the first.
1063-
* When function `f` returns true then an option containing the element
1064-
* is returned. If `f` matches no elements then none is returned.
1065-
*/
1066-
pub fn find<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
1067-
find_between(v, 0u, v.len(), f)
1068-
}
1069-
10701059
/**
10711060
* Search for the first element that matches a given predicate within a range
10721061
*
@@ -3163,18 +3152,6 @@ mod tests {
31633152
assert!(position_between(v, 4u, 4u, f).is_none());
31643153
}
31653154

3166-
#[test]
3167-
fn test_find() {
3168-
assert!(find([], f).is_none());
3169-
3170-
fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
3171-
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
3172-
let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
3173-
3174-
assert_eq!(find(v, f), Some((1, 'b')));
3175-
assert!(find(v, g).is_none());
3176-
}
3177-
31783155
#[test]
31793156
fn test_find_between() {
31803157
assert!(find_between([], 0u, 0u, f).is_none());
@@ -3205,8 +3182,6 @@ mod tests {
32053182

32063183
#[test]
32073184
fn test_rposition() {
3208-
assert!(find([], f).is_none());
3209-
32103185
fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
32113186
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
32123187
let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
@@ -3838,22 +3813,6 @@ mod tests {
38383813
};
38393814
}
38403815

3841-
#[test]
3842-
#[ignore(windows)]
3843-
#[should_fail]
3844-
#[allow(non_implicitly_copyable_typarams)]
3845-
fn test_find_fail() {
3846-
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
3847-
let mut i = 0;
3848-
do find(v) |_elt| {
3849-
if i == 2 {
3850-
fail!()
3851-
}
3852-
i += 0;
3853-
false
3854-
};
3855-
}
3856-
38573816
#[test]
38583817
#[ignore(windows)]
38593818
#[should_fail]

0 commit comments

Comments
 (0)