std: Transform.find_ -> .find
This commit is contained in:
parent
f9dee04aaa
commit
6fcf2ee8e3
@ -128,7 +128,7 @@ fn rustc_help() {
|
||||
}
|
||||
|
||||
fn find_cmd(command_string: &str) -> Option<Command> {
|
||||
do COMMANDS.iter().find_ |command| {
|
||||
do COMMANDS.iter().find |command| {
|
||||
command.cmd == command_string
|
||||
}.map_move(|x| *x)
|
||||
}
|
||||
|
@ -946,7 +946,7 @@ pub fn build_output_filenames(input: &input,
|
||||
let linkage_metas = attr::find_linkage_metas(attrs);
|
||||
if !linkage_metas.is_empty() {
|
||||
// But if a linkage meta is present, that overrides
|
||||
let maybe_name = linkage_metas.iter().find_(|m| "name" == m.name());
|
||||
let maybe_name = linkage_metas.iter().find(|m| "name" == m.name());
|
||||
match maybe_name.chain(|m| m.value_str()) {
|
||||
Some(s) => stem = s,
|
||||
_ => ()
|
||||
|
@ -183,7 +183,7 @@ fn visit_item(e: &Env, i: @ast::item) {
|
||||
match fm.sort {
|
||||
ast::named => {
|
||||
let link_name = i.attrs.iter()
|
||||
.find_(|at| "link_name" == at.name())
|
||||
.find(|at| "link_name" == at.name())
|
||||
.chain(|at| at.value_str());
|
||||
|
||||
let foreign_name = match link_name {
|
||||
|
@ -169,7 +169,7 @@ pub fn check_exhaustive(cx: &MatchCheckCtxt, sp: span, pats: ~[@pat]) {
|
||||
};
|
||||
let variants = ty::enum_variants(cx.tcx, id);
|
||||
|
||||
match variants.iter().find_(|v| v.id == vid) {
|
||||
match variants.iter().find(|v| v.id == vid) {
|
||||
Some(v) => Some(cx.tcx.sess.str_of(v.name)),
|
||||
None => {
|
||||
fail!("check_exhaustive: bad variant in ctor")
|
||||
@ -222,7 +222,7 @@ pub enum ctor {
|
||||
pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful {
|
||||
if m.len() == 0u { return useful_; }
|
||||
if m[0].len() == 0u { return not_useful; }
|
||||
let real_pat = match m.iter().find_(|r| r[0].id != 0) {
|
||||
let real_pat = match m.iter().find(|r| r[0].id != 0) {
|
||||
Some(r) => r[0], None => v[0]
|
||||
};
|
||||
let left_ty = if real_pat.id == 0 { ty::mk_nil() }
|
||||
@ -470,7 +470,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 ty::enum_variants(cx.tcx, eid).iter().find_(|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")
|
||||
}
|
||||
@ -627,7 +627,7 @@ pub fn specialize(cx: &MatchCheckCtxt,
|
||||
if variant(variant_id) == *ctor_id {
|
||||
// FIXME #4731: Is this right? --pcw
|
||||
let args = flds.map(|ty_field| {
|
||||
match flds.iter().find_(|f|
|
||||
match flds.iter().find(|f|
|
||||
f.ident == ty_field.ident) {
|
||||
Some(f) => f.pat,
|
||||
_ => wild()
|
||||
@ -658,7 +658,7 @@ pub fn specialize(cx: &MatchCheckCtxt,
|
||||
}
|
||||
}
|
||||
let args = class_fields.iter().map(|class_field| {
|
||||
match flds.iter().find_(|f|
|
||||
match flds.iter().find(|f|
|
||||
f.ident == class_field.ident) {
|
||||
Some(f) => f.pat,
|
||||
_ => wild()
|
||||
|
@ -588,7 +588,7 @@ fn enter_opt<'r>(bcx: @mut Block,
|
||||
let mut reordered_patterns = ~[];
|
||||
let r = ty::lookup_struct_fields(tcx, struct_id);
|
||||
for field in r.iter() {
|
||||
match field_pats.iter().find_(|p| p.ident == field.ident) {
|
||||
match field_pats.iter().find(|p| p.ident == field.ident) {
|
||||
None => reordered_patterns.push(dummy),
|
||||
Some(fp) => reordered_patterns.push(fp.pat)
|
||||
}
|
||||
@ -648,7 +648,7 @@ fn enter_rec_or_struct<'r>(bcx: @mut Block,
|
||||
ast::pat_struct(_, ref fpats, _) => {
|
||||
let mut pats = ~[];
|
||||
for fname in fields.iter() {
|
||||
match fpats.iter().find_(|p| p.ident == *fname) {
|
||||
match fpats.iter().find(|p| p.ident == *fname) {
|
||||
None => pats.push(dummy),
|
||||
Some(pat) => pats.push(pat.pat)
|
||||
}
|
||||
|
@ -1277,7 +1277,7 @@ pub fn cleanup_and_leave(bcx: @mut Block,
|
||||
let mut skip = 0;
|
||||
let mut dest = None;
|
||||
{
|
||||
let r = (*inf).cleanup_paths.rev_iter().find_(|cp| cp.target == leave);
|
||||
let r = (*inf).cleanup_paths.rev_iter().find(|cp| cp.target == leave);
|
||||
for cp in r.iter() {
|
||||
if cp.size == inf.cleanups.len() {
|
||||
Br(bcx, cp.dest);
|
||||
|
@ -500,7 +500,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef {
|
||||
|discr, field_tys| {
|
||||
let cs: ~[ValueRef] = field_tys.iter().enumerate()
|
||||
.map(|(ix, &field_ty)| {
|
||||
match fs.iter().find_(|f| field_ty.ident == f.ident) {
|
||||
match fs.iter().find(|f| field_ty.ident == f.ident) {
|
||||
Some(f) => const_expr(cx, (*f).expr),
|
||||
None => {
|
||||
match base_val {
|
||||
|
@ -288,7 +288,7 @@ pub fn method_with_name(ccx: &mut CrateContext,
|
||||
|
||||
let imp = ccx.tcx.impls.find(&impl_id)
|
||||
.expect("could not find impl while translating");
|
||||
let meth = imp.methods.iter().find_(|m| m.ident == name)
|
||||
let meth = imp.methods.iter().find(|m| m.ident == name)
|
||||
.expect("could not find method while translating");
|
||||
|
||||
ccx.impl_method_cache.insert((impl_id, name), meth.def_id);
|
||||
|
@ -245,7 +245,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 = *tvs.iter().find_(|tv| { tv.id.node == fn_id.node}).unwrap();
|
||||
let this_tv = *tvs.iter().find(|tv| { tv.id.node == fn_id.node}).unwrap();
|
||||
let d = mk_lldecl();
|
||||
set_inline_hint(d);
|
||||
match v.node.kind {
|
||||
|
@ -4117,7 +4117,7 @@ pub fn lookup_struct_field(cx: ctxt,
|
||||
field_id: ast::def_id)
|
||||
-> field_ty {
|
||||
let r = lookup_struct_fields(cx, parent);
|
||||
match r.iter().find_(
|
||||
match r.iter().find(
|
||||
|f| f.id.node == field_id.node) {
|
||||
Some(t) => *t,
|
||||
None => cx.sess.bug("struct ID not found in parent's fields")
|
||||
|
@ -1122,7 +1122,7 @@ pub fn lookup_field_ty(tcx: ty::ctxt,
|
||||
fieldname: ast::ident,
|
||||
substs: &ty::substs) -> Option<ty::t> {
|
||||
|
||||
let o_field = items.iter().find_(|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)
|
||||
}
|
||||
|
@ -675,7 +675,7 @@ pub fn check_methods_against_trait(ccx: &CrateCtxt,
|
||||
// we'll catch it in coherence
|
||||
let trait_ms = ty::trait_methods(tcx, trait_ref.def_id);
|
||||
for impl_m in impl_ms.iter() {
|
||||
match trait_ms.iter().find_(|trait_m| trait_m.ident == impl_m.mty.ident) {
|
||||
match trait_ms.iter().find(|trait_m| trait_m.ident == impl_m.mty.ident) {
|
||||
Some(trait_m) => {
|
||||
let num_impl_tps = generics.ty_params.len();
|
||||
compare_impl_method(
|
||||
|
@ -133,7 +133,7 @@ fn fold_enum(
|
||||
node: ast::item_enum(ref enum_definition, _), _
|
||||
}, _) => {
|
||||
let ast_variant =
|
||||
(*enum_definition.variants.iter().find_(|v| {
|
||||
(*enum_definition.variants.iter().find(|v| {
|
||||
to_str(v.node.name) == variant.name
|
||||
}).unwrap()).clone();
|
||||
|
||||
|
@ -221,7 +221,7 @@ pub fn maybe_find_pandoc(
|
||||
}
|
||||
};
|
||||
|
||||
let pandoc = do possible_pandocs.iter().find_ |&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
|
||||
|
@ -81,7 +81,7 @@ fn strip_priv_methods(
|
||||
item_vis: ast::visibility
|
||||
) -> doc::ImplDoc {
|
||||
let methods = do doc.methods.iter().filter |method| {
|
||||
let ast_method = do methods.iter().find_ |m| {
|
||||
let ast_method = do methods.iter().find |m| {
|
||||
extract::to_str(m.ident) == method.name
|
||||
};
|
||||
assert!(ast_method.is_some());
|
||||
|
@ -133,7 +133,7 @@ fn fold_enum(
|
||||
node: ast::item_enum(ref enum_definition, _), _
|
||||
}, _) => {
|
||||
let ast_variant =
|
||||
(*do enum_definition.variants.iter().find_ |v| {
|
||||
(*do enum_definition.variants.iter().find |v| {
|
||||
to_str(v.node.name) == variant.name
|
||||
}.unwrap()).clone();
|
||||
|
||||
@ -187,7 +187,7 @@ fn get_method_sig(
|
||||
ast_map::node_item(@ast::item {
|
||||
node: ast::item_trait(_, _, ref methods), _
|
||||
}, _) => {
|
||||
match methods.iter().find_(|&method| {
|
||||
match methods.iter().find(|&method| {
|
||||
match (*method).clone() {
|
||||
ast::required(ty_m) => to_str(ty_m.ident) == method_name,
|
||||
ast::provided(m) => to_str(m.ident) == method_name,
|
||||
@ -223,7 +223,7 @@ fn get_method_sig(
|
||||
ast_map::node_item(@ast::item {
|
||||
node: ast::item_impl(_, _, _, ref methods), _
|
||||
}, _) => {
|
||||
match methods.iter().find_(|method| {
|
||||
match methods.iter().find(|method| {
|
||||
to_str(method.ident) == method_name
|
||||
}) {
|
||||
Some(method) => {
|
||||
|
@ -315,7 +315,7 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option<bool> {
|
||||
// file, skip compilation and return None.
|
||||
let mut should_compile = true;
|
||||
let dir = os::list_dir_path(&Path(outputs.out_filename.dirname()));
|
||||
let maybe_lib_path = do dir.iter().find_ |file| {
|
||||
let maybe_lib_path = do dir.iter().find |file| {
|
||||
// The actual file's name has a hash value and version
|
||||
// number in it which is unknown at this time, so looking
|
||||
// for a file that matches out_filename won't work,
|
||||
|
@ -55,7 +55,7 @@ fn check_dir(&self) -> Path {
|
||||
let dir;
|
||||
let dirs = pkgid_src_in_workspace(&self.id, &self.root);
|
||||
debug!("Checking dirs: %?", dirs);
|
||||
let path = dirs.iter().find_(|&d| os::path_exists(d));
|
||||
let path = dirs.iter().find(|&d| os::path_exists(d));
|
||||
match path {
|
||||
Some(d) => dir = (*d).clone(),
|
||||
None => dir = match self.fetch_git() {
|
||||
|
@ -458,7 +458,7 @@ fn any(&mut self, f: &fn(A) -> bool) -> bool {
|
||||
|
||||
/// Return the first element satisfying the specified predicate
|
||||
#[inline]
|
||||
fn find_(&mut self, predicate: &fn(&A) -> bool) -> Option<A> {
|
||||
fn find(&mut self, predicate: &fn(&A) -> bool) -> Option<A> {
|
||||
for x in *self {
|
||||
if predicate(&x) { return Some(x) }
|
||||
}
|
||||
@ -1819,9 +1819,9 @@ fn test_any() {
|
||||
#[test]
|
||||
fn test_find() {
|
||||
let v: &[int] = &[1, 3, 9, 27, 103, 14, 11];
|
||||
assert_eq!(*v.iter().find_(|x| *x & 1 == 0).unwrap(), 14);
|
||||
assert_eq!(*v.iter().find_(|x| *x % 3 == 0).unwrap(), 3);
|
||||
assert!(v.iter().find_(|x| *x % 12 == 0).is_none());
|
||||
assert_eq!(*v.iter().find(|x| *x & 1 == 0).unwrap(), 14);
|
||||
assert_eq!(*v.iter().find(|x| *x % 3 == 0).unwrap(), 3);
|
||||
assert!(v.iter().find(|x| *x % 12 == 0).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -59,7 +59,7 @@ pub fn from_bytes(vv: &[u8]) -> ~str {
|
||||
use str::not_utf8::cond;
|
||||
|
||||
if !is_utf8(vv) {
|
||||
let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).unwrap();
|
||||
let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap();
|
||||
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
|
||||
first_bad_byte as uint))
|
||||
} else {
|
||||
@ -76,7 +76,7 @@ pub fn from_bytes_owned(vv: ~[u8]) -> ~str {
|
||||
use str::not_utf8::cond;
|
||||
|
||||
if !is_utf8(vv) {
|
||||
let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).unwrap();
|
||||
let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap();
|
||||
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
|
||||
first_bad_byte as uint))
|
||||
} else {
|
||||
|
@ -186,13 +186,13 @@ pub fn contains_name<AM: AttrMetaMethods>(metas: &[AM], name: &str) -> bool {
|
||||
pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str)
|
||||
-> Option<@str> {
|
||||
attrs.iter()
|
||||
.find_(|at| name == at.name())
|
||||
.find(|at| name == at.name())
|
||||
.chain(|at| at.value_str())
|
||||
}
|
||||
|
||||
pub fn last_meta_item_value_str_by_name(items: &[@MetaItem], name: &str)
|
||||
-> Option<@str> {
|
||||
items.rev_iter().find_(|mi| name == mi.name()).chain(|i| i.value_str())
|
||||
items.rev_iter().find(|mi| name == mi.name()).chain(|i| i.value_str())
|
||||
}
|
||||
|
||||
/* Higher-level applications */
|
||||
|
Loading…
Reference in New Issue
Block a user