auto merge of #5212 : thestinger/rust/iter, r=graydon
A small step towards fixing #2827
This commit is contained in:
commit
eddefbc893
39 changed files with 120 additions and 118 deletions
|
|
@ -59,11 +59,11 @@ pub fn load_props(testfile: &Path) -> TestProps {
|
|||
pp_exact = parse_pp_exact(ln, testfile);
|
||||
}
|
||||
|
||||
do parse_aux_build(ln).iter |ab| {
|
||||
for parse_aux_build(ln).each |ab| {
|
||||
aux_builds.push(*ab);
|
||||
}
|
||||
|
||||
do parse_exec_env(ln).iter |ee| {
|
||||
for parse_exec_env(ln).each |ee| {
|
||||
exec_env.push(*ee);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,8 +132,6 @@ pub mod container;
|
|||
/* Common data structures */
|
||||
|
||||
pub mod option;
|
||||
#[path="iter-trait.rs"] #[merge = "iter-trait/option.rs"]
|
||||
pub mod option_iter;
|
||||
pub mod result;
|
||||
pub mod either;
|
||||
pub mod dvec;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ use cmp::{Eq,Ord};
|
|||
use kinds::Copy;
|
||||
use util;
|
||||
use num::Zero;
|
||||
use iter::BaseIter;
|
||||
|
||||
#[cfg(test)] use ptr;
|
||||
#[cfg(test)] use str;
|
||||
|
|
@ -228,12 +229,6 @@ pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U,
|
|||
match *opt { None => def, Some(ref t) => f(t) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn iter<T>(opt: &r/Option<T>, f: fn(x: &r/T)) {
|
||||
//! Performs an operation on the contained value by reference
|
||||
match *opt { None => (), Some(ref t) => f(t) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn unwrap<T>(opt: Option<T>) -> T {
|
||||
/*!
|
||||
|
|
@ -281,6 +276,19 @@ pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> BaseIter<T> for Option<T> {
|
||||
/// Performs an operation on the contained value by reference
|
||||
#[inline(always)]
|
||||
pure fn each(&self, f: fn(x: &self/T) -> bool) {
|
||||
match *self { None => (), Some(ref t) => { f(t); } }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn size_hint(&self) -> Option<uint> {
|
||||
if self.is_some() { Some(1) } else { Some(0) }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> Option<T> {
|
||||
/// Returns true if the option equals `none`
|
||||
#[inline(always)]
|
||||
|
|
@ -339,10 +347,6 @@ pub impl<T> Option<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Performs an operation on the contained value by reference
|
||||
#[inline(always)]
|
||||
pure fn iter(&self, f: fn(x: &self/T)) { iter(self, f) }
|
||||
|
||||
/**
|
||||
Gets an immutable reference to the value inside an option.
|
||||
|
||||
|
|
@ -476,7 +480,7 @@ fn test_option_dance() {
|
|||
let x = Some(());
|
||||
let mut y = Some(5);
|
||||
let mut y2 = 0;
|
||||
do x.iter |_x| {
|
||||
for x.each |_x| {
|
||||
y2 = swap_unwrap(&mut y);
|
||||
}
|
||||
assert y2 == 5;
|
||||
|
|
|
|||
|
|
@ -1241,7 +1241,7 @@ mod tests {
|
|||
setenv(~"HOME", ~"");
|
||||
assert os::homedir().is_none();
|
||||
|
||||
oldhome.iter(|s| setenv(~"HOME", *s));
|
||||
for oldhome.each |s| { setenv(~"HOME", *s) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ fn each_ancestor(list: &mut AncestorList,
|
|||
* Step 3: Maybe unwind; compute return info for our caller.
|
||||
*##########################################################*/
|
||||
if need_unwind && !nobe_is_dead {
|
||||
do bail_opt.iter |bail_blk| {
|
||||
for bail_opt.each |bail_blk| {
|
||||
do with_parent_tg(&mut nobe.parent_group) |tg_opt| {
|
||||
(*bail_blk)(tg_opt)
|
||||
}
|
||||
|
|
@ -315,7 +315,7 @@ impl Drop for TCB {
|
|||
unsafe {
|
||||
// If we are failing, the whole taskgroup needs to die.
|
||||
if rt::rust_task_is_unwinding(self.me) {
|
||||
self.notifier.iter(|x| { x.failed = true; });
|
||||
for self.notifier.each |x| { x.failed = true; }
|
||||
// Take everybody down with us.
|
||||
do access_group(&self.tasks) |tg| {
|
||||
kill_taskgroup(tg, self.me, self.is_main);
|
||||
|
|
@ -339,9 +339,7 @@ impl Drop for TCB {
|
|||
|
||||
fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
|
||||
is_main: bool, notifier: Option<AutoNotify>) -> TCB {
|
||||
|
||||
let notifier = notifier;
|
||||
notifier.iter(|x| { x.failed = false; });
|
||||
for notifier.each |x| { x.failed = false; }
|
||||
|
||||
TCB {
|
||||
me: me,
|
||||
|
|
|
|||
|
|
@ -710,7 +710,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
|||
let idx = encode_info_for_struct(ecx, ebml_w, path,
|
||||
struct_def.fields, index);
|
||||
/* Encode the dtor */
|
||||
do struct_def.dtor.iter |dtor| {
|
||||
for struct_def.dtor.each |dtor| {
|
||||
index.push(entry {val: dtor.node.id, pos: ebml_w.writer.tell()});
|
||||
encode_info_for_ctor(ecx,
|
||||
ebml_w,
|
||||
|
|
@ -762,7 +762,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
|||
encode_region_param(ecx, ebml_w, item);
|
||||
/* Encode the dtor */
|
||||
/* Encode id for dtor */
|
||||
do struct_def.dtor.iter |dtor| {
|
||||
for struct_def.dtor.each |dtor| {
|
||||
do ebml_w.wr_tag(tag_item_dtor) {
|
||||
encode_def_id(ebml_w, local_def(dtor.node.id));
|
||||
}
|
||||
|
|
@ -816,7 +816,7 @@ fn encode_info_for_item(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
|||
ebml_w.writer.write(str::to_bytes(def_to_str(method_def_id)));
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
do opt_trait.iter() |associated_trait| {
|
||||
for opt_trait.each |associated_trait| {
|
||||
encode_trait_ref(ebml_w, ecx, *associated_trait);
|
||||
}
|
||||
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
|
||||
|
|
|
|||
|
|
@ -854,7 +854,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
|
||||
debug!("Encoding side tables for id %d", id);
|
||||
|
||||
do option::iter(&tcx.def_map.find(&id)) |def| {
|
||||
for tcx.def_map.find(&id).each |def| {
|
||||
do ebml_w.tag(c::tag_table_def) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -862,7 +862,8 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
}
|
||||
}
|
||||
}
|
||||
do option::iter(&tcx.node_types.find(&(id as uint))) |&ty| {
|
||||
|
||||
for tcx.node_types.find(&(id as uint)).each |&ty| {
|
||||
do ebml_w.tag(c::tag_table_node_type) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -871,7 +872,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
}
|
||||
}
|
||||
|
||||
do option::iter(&tcx.node_type_substs.find(&id)) |tys| {
|
||||
for tcx.node_type_substs.find(&id).each |tys| {
|
||||
do ebml_w.tag(c::tag_table_node_type_subst) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -880,7 +881,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
}
|
||||
}
|
||||
|
||||
do option::iter(&tcx.freevars.find(&id)) |fv| {
|
||||
for tcx.freevars.find(&id).each |fv| {
|
||||
do ebml_w.tag(c::tag_table_freevars) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -892,7 +893,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
}
|
||||
|
||||
let lid = ast::def_id { crate: ast::local_crate, node: id };
|
||||
do option::iter(&tcx.tcache.find(&lid)) |tpbt| {
|
||||
for tcx.tcache.find(&lid).each |tpbt| {
|
||||
do ebml_w.tag(c::tag_table_tcache) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -901,7 +902,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
}
|
||||
}
|
||||
|
||||
do option::iter(&tcx.ty_param_bounds.find(&id)) |pbs| {
|
||||
for tcx.ty_param_bounds.find(&id).each |pbs| {
|
||||
do ebml_w.tag(c::tag_table_param_bounds) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -915,7 +916,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
// is what we actually use in trans, all modes will have been
|
||||
// resolved.
|
||||
//
|
||||
//option::iter(tcx.inferred_modes.find(&id)) {|m|
|
||||
//for tcx.inferred_modes.find(&id).each |m| {
|
||||
// ebml_w.tag(c::tag_table_inferred_modes) {||
|
||||
// ebml_w.id(id);
|
||||
// ebml_w.tag(c::tag_table_val) {||
|
||||
|
|
@ -924,13 +925,13 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
// }
|
||||
//}
|
||||
|
||||
do option::iter(&maps.mutbl_map.find(&id)) |_m| {
|
||||
if maps.mutbl_map.contains_key(&id) {
|
||||
do ebml_w.tag(c::tag_table_mutbl) {
|
||||
ebml_w.id(id);
|
||||
}
|
||||
}
|
||||
|
||||
do option::iter(&maps.last_use_map.find(&id)) |m| {
|
||||
for maps.last_use_map.find(&id).each |m| {
|
||||
do ebml_w.tag(c::tag_table_last_use) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -941,7 +942,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
}
|
||||
}
|
||||
|
||||
do option::iter(&maps.method_map.find(&id)) |mme| {
|
||||
for maps.method_map.find(&id).each |mme| {
|
||||
do ebml_w.tag(c::tag_table_method_map) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -950,7 +951,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
}
|
||||
}
|
||||
|
||||
do option::iter(&maps.vtable_map.find(&id)) |dr| {
|
||||
for maps.vtable_map.find(&id).each |dr| {
|
||||
do ebml_w.tag(c::tag_table_vtable_map) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
@ -959,7 +960,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
|
|||
}
|
||||
}
|
||||
|
||||
do option::iter(&tcx.adjustments.find(&id)) |adj| {
|
||||
for tcx.adjustments.find(&id).each |adj| {
|
||||
do ebml_w.tag(c::tag_table_adjustments) {
|
||||
ebml_w.id(id);
|
||||
do ebml_w.tag(c::tag_table_val) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ pub fn check_item(sess: Session,
|
|||
}
|
||||
item_enum(ref enum_definition, _) => {
|
||||
for (*enum_definition).variants.each |var| {
|
||||
do option::iter(&var.node.disr_expr) |ex| {
|
||||
for var.node.disr_expr.each |ex| {
|
||||
(v.visit_expr)(*ex, true, v);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ pub fn missing_ctor(cx: @MatchCheckCtxt,
|
|||
ty::ty_enum(eid, _) => {
|
||||
let mut found = ~[];
|
||||
for m.each |r| {
|
||||
do option::iter(&pat_ctor_id(cx, r[0])) |id| {
|
||||
for pat_ctor_id(cx, r[0]).each |id| {
|
||||
if !vec::contains(found, id) {
|
||||
found.push(/*bad*/copy *id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
|
|||
expr_unary(*)|expr_binary(*)|expr_method_call(*) => e.callee_id,
|
||||
_ => e.id
|
||||
};
|
||||
do option::iter(&cx.tcx.node_type_substs.find(&type_parameter_id)) |ts| {
|
||||
for cx.tcx.node_type_substs.find(&type_parameter_id).each |ts| {
|
||||
let bounds = match e.node {
|
||||
expr_path(_) => {
|
||||
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&e.id));
|
||||
|
|
@ -253,7 +253,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
|
|||
fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
|
||||
match aty.node {
|
||||
ty_path(_, id) => {
|
||||
do option::iter(&cx.tcx.node_type_substs.find(&id)) |ts| {
|
||||
for cx.tcx.node_type_substs.find(&id).each |ts| {
|
||||
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(&id));
|
||||
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
|
||||
for vec::each2(*ts, *bounds) |ty, bound| {
|
||||
|
|
|
|||
|
|
@ -1101,7 +1101,7 @@ pub impl Liveness {
|
|||
|
||||
fn propagate_through_opt_expr(&self, opt_expr: Option<@expr>,
|
||||
succ: LiveNode) -> LiveNode {
|
||||
do opt_expr.foldl(succ) |succ, expr| {
|
||||
do iter::foldl(&opt_expr, succ) |succ, expr| {
|
||||
self.propagate_through_expr(*expr, *succ)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1016,7 +1016,7 @@ pub impl Resolver {
|
|||
fmt!("duplicate definition of %s %s",
|
||||
namespace_to_str(ns),
|
||||
*self.session.str_of(name)));
|
||||
do child.span_for_namespace(ns).iter() |sp| {
|
||||
for child.span_for_namespace(ns).each |sp| {
|
||||
self.session.span_note(*sp,
|
||||
fmt!("first definition of %s %s here:",
|
||||
namespace_to_str(ns),
|
||||
|
|
@ -3457,7 +3457,7 @@ pub impl Resolver {
|
|||
// then resolve the ty params
|
||||
item_enum(ref enum_def, ref generics) => {
|
||||
for (*enum_def).variants.each() |variant| {
|
||||
do variant.node.disr_expr.iter() |dis_expr| {
|
||||
for variant.node.disr_expr.each |dis_expr| {
|
||||
// resolve the discriminator expr
|
||||
// as a constant
|
||||
self.with_constant_rib(|| {
|
||||
|
|
|
|||
|
|
@ -1211,10 +1211,10 @@ pub fn new_block(cx: fn_ctxt, parent: Option<block>, +kind: block_kind,
|
|||
is_lpad,
|
||||
opt_node_info,
|
||||
cx);
|
||||
do option::iter(&parent) |cx| {
|
||||
for parent.each |cx| {
|
||||
if cx.unreachable { Unreachable(bcx); }
|
||||
};
|
||||
return bcx;
|
||||
bcx
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1442,7 +1442,7 @@ pub fn alloc_local(cx: block, local: @ast::local) -> block {
|
|||
};
|
||||
let val = alloc_ty(cx, t);
|
||||
if cx.sess().opts.debuginfo {
|
||||
do option::iter(&simple_name) |name| {
|
||||
for simple_name.each |name| {
|
||||
str::as_c_str(*cx.ccx().sess.str_of(*name), |buf| {
|
||||
unsafe {
|
||||
llvm::LLVMSetValueName(val, buf)
|
||||
|
|
@ -1451,7 +1451,7 @@ pub fn alloc_local(cx: block, local: @ast::local) -> block {
|
|||
}
|
||||
}
|
||||
cx.fcx.lllocals.insert(local.node.id, local_mem(val));
|
||||
return cx;
|
||||
cx
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -2011,7 +2011,7 @@ pub fn trans_struct_dtor(ccx: @CrateContext,
|
|||
/* Look up the parent class's def_id */
|
||||
let mut class_ty = ty::lookup_item_type(tcx, parent_id).ty;
|
||||
/* Substitute in the class type if necessary */
|
||||
do option::iter(&psubsts) |ss| {
|
||||
for psubsts.each |ss| {
|
||||
class_ty = ty::subst_tps(tcx, ss.tys, ss.self_ty, class_ty);
|
||||
}
|
||||
|
||||
|
|
@ -2028,7 +2028,7 @@ pub fn trans_struct_dtor(ccx: @CrateContext,
|
|||
|
||||
/* If we're monomorphizing, register the monomorphized decl
|
||||
for the dtor */
|
||||
do option::iter(&hash_id) |h_id| {
|
||||
for hash_id.each |h_id| {
|
||||
ccx.monomorphized.insert(*h_id, lldecl);
|
||||
}
|
||||
/* Translate the dtor body */
|
||||
|
|
@ -2142,7 +2142,7 @@ pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::struct_def,
|
|||
path: @ast_map::path,
|
||||
id: ast::node_id) {
|
||||
// Translate the destructor.
|
||||
do option::iter(&struct_def.dtor) |dtor| {
|
||||
for struct_def.dtor.each |dtor| {
|
||||
trans_struct_dtor(ccx, /*bad*/copy *path, &dtor.node.body,
|
||||
dtor.node.id, None, None, local_def(id));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -535,7 +535,7 @@ pub fn trans_call_inner(
|
|||
} else if ret_in_loop {
|
||||
let ret_flag_result = bool_to_i1(bcx, Load(bcx, ret_flag.get()));
|
||||
bcx = do with_cond(bcx, ret_flag_result) |bcx| {
|
||||
do option::iter(© bcx.fcx.loop_ret) |&(flagptr, _)| {
|
||||
for (copy bcx.fcx.loop_ret).each |&(flagptr, _)| {
|
||||
Store(bcx, C_bool(true), flagptr);
|
||||
Store(bcx, C_bool(false), bcx.fcx.llretptr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ pub fn build_closure(bcx0: block,
|
|||
|
||||
// If this is a `for` loop body, add two special environment
|
||||
// variables:
|
||||
do option::iter(&include_ret_handle) |flagptr| {
|
||||
for include_ret_handle.each |flagptr| {
|
||||
// Flag indicating we have returned (a by-ref bool):
|
||||
let flag_datum = Datum {val: *flagptr, ty: ty::mk_bool(tcx),
|
||||
mode: ByRef, source: ZeroMem};
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
|
|||
for struct_def.ctor_id.each |&ctor_id| {
|
||||
cx.rmap.insert(ctor_id, ());
|
||||
}
|
||||
do struct_def.dtor.iter |dtor| {
|
||||
for struct_def.dtor.each |dtor| {
|
||||
cx.rmap.insert(dtor.node.id, ());
|
||||
if generics.ty_params.len() > 0u ||
|
||||
attr::find_inline_attr(dtor.node.attrs) != attr::ia_none
|
||||
|
|
|
|||
|
|
@ -239,10 +239,10 @@ pub fn node_type_needs(cx: Context, use_: uint, id: node_id) {
|
|||
}
|
||||
|
||||
pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
|
||||
do option::iter(&cx.ccx.maps.method_map.find(&e_id)) |mth| {
|
||||
for cx.ccx.maps.method_map.find(&e_id).each |mth| {
|
||||
match mth.origin {
|
||||
typeck::method_static(did) => {
|
||||
do cx.ccx.tcx.node_type_substs.find(&callee_id).iter |ts| {
|
||||
for cx.ccx.tcx.node_type_substs.find(&callee_id).each |ts| {
|
||||
let type_uses = type_uses_for(cx.ccx, did, ts.len());
|
||||
for vec::each2(type_uses, *ts) |uses, subst| {
|
||||
type_needs(cx, *uses, *subst)
|
||||
|
|
@ -291,7 +291,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
|
|||
}
|
||||
}
|
||||
expr_path(_) => {
|
||||
do cx.ccx.tcx.node_type_substs.find(&e.id).iter |ts| {
|
||||
for cx.ccx.tcx.node_type_substs.find(&e.id).each |ts| {
|
||||
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(&e.id));
|
||||
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
|
||||
for vec::each2(uses_for_ts, *ts) |uses, subst| {
|
||||
|
|
@ -377,7 +377,7 @@ pub fn handle_body(cx: Context, body: &blk) {
|
|||
},
|
||||
visit_block: |b, cx, v| {
|
||||
visit::visit_block(b, cx, v);
|
||||
do option::iter(&b.node.expr) |e| {
|
||||
for b.node.expr.each |e| {
|
||||
node_type_needs(cx, use_repr, e.id);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -870,7 +870,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
|
|||
fn sflags(substs: &substs) -> uint {
|
||||
let mut f = 0u;
|
||||
for substs.tps.each |tt| { f |= get(*tt).flags; }
|
||||
substs.self_r.iter(|r| f |= rflags(*r));
|
||||
for substs.self_r.each |r| { f |= rflags(*r) }
|
||||
return f;
|
||||
}
|
||||
match &st {
|
||||
|
|
|
|||
|
|
@ -181,11 +181,11 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
|
|||
tcx.sess.span_fatal(pat.span, s);
|
||||
}
|
||||
|
||||
do subpats.iter() |pats| {
|
||||
for subpats.each |pats| {
|
||||
for vec::each2(*pats, arg_types) |subpat, arg_ty| {
|
||||
check_pat(pcx, *subpat, *arg_ty);
|
||||
}
|
||||
};
|
||||
}
|
||||
} else if subpats_len > 0u {
|
||||
tcx.sess.span_fatal
|
||||
(pat.span, fmt!("this pattern has %u field%s, but the \
|
||||
|
|
|
|||
|
|
@ -535,7 +535,7 @@ pub fn check_struct(ccx: @mut CrateCtxt,
|
|||
let tcx = ccx.tcx;
|
||||
let self_ty = ty::node_id_to_type(tcx, id);
|
||||
|
||||
do struct_def.dtor.iter() |dtor| {
|
||||
for struct_def.dtor.each |dtor| {
|
||||
let class_t = SelfInfo {
|
||||
self_ty: self_ty,
|
||||
self_id: dtor.node.self_id,
|
||||
|
|
@ -2817,7 +2817,7 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
|
|||
variants: &mut ~[ty::VariantInfo]) {
|
||||
let rty = ty::node_id_to_type(ccx.tcx, id);
|
||||
for vs.each |v| {
|
||||
do v.node.disr_expr.iter |e_ref| {
|
||||
for v.node.disr_expr.each |e_ref| {
|
||||
let e = *e_ref;
|
||||
debug!("disr expr, checking %s",
|
||||
pprust::expr_to_str(e, ccx.tcx.sess.intr()));
|
||||
|
|
|
|||
|
|
@ -205,7 +205,8 @@ pub impl CoherenceChecker {
|
|||
|
||||
match item.node {
|
||||
item_impl(_, opt_trait, _, _) => {
|
||||
self.check_implementation(item, opt_trait.to_vec());
|
||||
self.check_implementation(item,
|
||||
iter::to_vec(&opt_trait));
|
||||
}
|
||||
_ => {
|
||||
// Nothing to do.
|
||||
|
|
@ -672,7 +673,7 @@ pub impl CoherenceChecker {
|
|||
_ => ()
|
||||
}
|
||||
|
||||
do opt_trait.iter() |trait_ref| {
|
||||
for opt_trait.each |trait_ref| {
|
||||
// This is OK if and only if the trait was
|
||||
// defined in this crate.
|
||||
|
||||
|
|
|
|||
|
|
@ -688,7 +688,7 @@ pub fn convert_struct(ccx: @mut CrateCtxt,
|
|||
id: ast::node_id) {
|
||||
let tcx = ccx.tcx;
|
||||
|
||||
do option::iter(&struct_def.dtor) |dtor| {
|
||||
for struct_def.dtor.each |dtor| {
|
||||
// Write the dtor type
|
||||
let t_dtor = ty::mk_bare_fn(
|
||||
tcx,
|
||||
|
|
|
|||
|
|
@ -720,8 +720,9 @@ pub impl @mut InferCtxt {
|
|||
self.tcx.sess.span_err(sp,
|
||||
fmt!("%s%s", mk_msg(self.ty_to_str(actual_ty)),
|
||||
error_str));
|
||||
err.iter(|err|
|
||||
ty::note_and_explain_type_err(self.tcx, *err));
|
||||
for err.each |err| {
|
||||
ty::note_and_explain_type_err(self.tcx, *err)
|
||||
}
|
||||
}
|
||||
|
||||
fn report_mismatched_types(&self, sp: span, e: ty::t, a: ty::t,
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ pub impl<K: TotalOrd, V> TreeNode<K, V> {
|
|||
|
||||
pure fn each<K: TotalOrd, V>(node: &r/Option<~TreeNode<K, V>>,
|
||||
f: fn(&(&r/K, &r/V)) -> bool) {
|
||||
do node.iter |x| {
|
||||
for node.each |x| {
|
||||
each(&x.left, f);
|
||||
if f(&(&x.key, &x.value)) { each(&x.right, f) }
|
||||
}
|
||||
|
|
@ -536,7 +536,7 @@ pure fn each<K: TotalOrd, V>(node: &r/Option<~TreeNode<K, V>>,
|
|||
|
||||
pure fn each_reverse<K: TotalOrd, V>(node: &r/Option<~TreeNode<K, V>>,
|
||||
f: fn(&(&r/K, &r/V)) -> bool) {
|
||||
do node.iter |x| {
|
||||
for node.each |x| {
|
||||
each_reverse(&x.right, f);
|
||||
if f(&(&x.key, &x.value)) { each_reverse(&x.left, f) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ pub fn walk_pat(pat: @pat, it: fn(@pat)) {
|
|||
for elts.each |p| {
|
||||
walk_pat(*p, it)
|
||||
}
|
||||
do tail.iter |tail| {
|
||||
for tail.each |tail| {
|
||||
walk_pat(*tail, it)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ fn highlight_lines(cm: @codemap::CodeMap,
|
|||
}
|
||||
|
||||
fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) {
|
||||
do option::iter(&sp.expn_info) |ei| {
|
||||
for sp.expn_info.each |ei| {
|
||||
let ss = option::map_default(&ei.callee.span, @~"",
|
||||
|span| @cm.span_to_str(*span));
|
||||
print_diagnostic(*ss, note,
|
||||
|
|
|
|||
|
|
@ -732,7 +732,7 @@ pub fn print_struct(s: @ps,
|
|||
nbsp(s);
|
||||
bopen(s);
|
||||
hardbreak_if_not_bol(s);
|
||||
do struct_def.dtor.iter |dtor| {
|
||||
for struct_def.dtor.each |dtor| {
|
||||
hardbreak_if_not_bol(s);
|
||||
maybe_print_comment(s, dtor.span.lo);
|
||||
print_outer_attributes(s, dtor.node.attrs);
|
||||
|
|
@ -1271,10 +1271,10 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
|
|||
ast::expr_loop(ref blk, opt_ident) => {
|
||||
head(s, ~"loop");
|
||||
space(s.s);
|
||||
opt_ident.iter(|ident| {
|
||||
for opt_ident.each |ident| {
|
||||
print_ident(s, *ident);
|
||||
word_space(s, ~":");
|
||||
});
|
||||
}
|
||||
print_block(s, blk);
|
||||
}
|
||||
ast::expr_match(expr, ref arms) => {
|
||||
|
|
@ -1422,12 +1422,12 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
|
|||
ast::expr_break(opt_ident) => {
|
||||
word(s.s, ~"break");
|
||||
space(s.s);
|
||||
opt_ident.iter(|ident| {print_ident(s, *ident); space(s.s)});
|
||||
for opt_ident.each |ident| { print_ident(s, *ident); space(s.s) }
|
||||
}
|
||||
ast::expr_again(opt_ident) => {
|
||||
word(s.s, ~"loop");
|
||||
space(s.s);
|
||||
opt_ident.iter(|ident| {print_ident(s, *ident); space(s.s)});
|
||||
for opt_ident.each |ident| { print_ident(s, *ident); space(s.s) }
|
||||
}
|
||||
ast::expr_ret(result) => {
|
||||
word(s.s, ~"return");
|
||||
|
|
@ -1667,7 +1667,7 @@ pub fn print_pat(s: @ps, &&pat: @ast::pat, refutable: bool) {
|
|||
ast::pat_vec(elts, tail) => {
|
||||
word(s.s, ~"[");
|
||||
commasep(s, inconsistent, elts, |s, p| print_pat(s, p, refutable));
|
||||
do option::iter(&tail) |tail| {
|
||||
for tail.each |tail| {
|
||||
if vec::len(elts) != 0u { word_space(s, ~","); }
|
||||
word(s.s, ~"..");
|
||||
print_pat(s, *tail, refutable);
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ pub fn visit_enum_def<E>(enum_definition: ast::enum_def,
|
|||
}
|
||||
}
|
||||
// Visit the disr expr if it exists
|
||||
vr.node.disr_expr.iter(|ex| (v.visit_expr)(*ex, e, v));
|
||||
for vr.node.disr_expr.each |ex| { (v.visit_expr)(*ex, e, v) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ pub fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
|
|||
match p.node {
|
||||
pat_enum(path, ref children) => {
|
||||
visit_path(path, e, v);
|
||||
do children.iter |children| {
|
||||
for children.each |children| {
|
||||
for children.each |child| { (v.visit_pat)(*child, e, v); }
|
||||
}
|
||||
}
|
||||
|
|
@ -289,7 +289,7 @@ pub fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
|
|||
},
|
||||
pat_ident(_, path, ref inner) => {
|
||||
visit_path(path, e, v);
|
||||
do inner.iter |subpat| { (v.visit_pat)(*subpat, e, v) }
|
||||
for inner.each |subpat| { (v.visit_pat)(*subpat, e, v) }
|
||||
}
|
||||
pat_lit(ex) => (v.visit_expr)(ex, e, v),
|
||||
pat_range(e1, e2) => {
|
||||
|
|
@ -301,7 +301,7 @@ pub fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
|
|||
for elts.each |elt| {
|
||||
(v.visit_pat)(*elt, e, v);
|
||||
}
|
||||
do tail.iter |tail| {
|
||||
for tail.each |tail| {
|
||||
(v.visit_pat)(*tail, e, v);
|
||||
}
|
||||
}
|
||||
|
|
@ -415,7 +415,7 @@ pub fn visit_struct_def<E>(
|
|||
for sd.fields.each |f| {
|
||||
(v.visit_struct_field)(*f, e, v);
|
||||
}
|
||||
do sd.dtor.iter |dtor| {
|
||||
for sd.dtor.each |dtor| {
|
||||
visit_struct_dtor_helper(
|
||||
*dtor,
|
||||
generics,
|
||||
|
|
@ -423,7 +423,7 @@ pub fn visit_struct_def<E>(
|
|||
e,
|
||||
v
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn visit_struct_field<E>(sf: @struct_field, e: E, v: vt<E>) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub fn main() {
|
|||
assert [2u, 4u].all(is_even);
|
||||
assert [].all(is_even);
|
||||
|
||||
assert !Some(1u).all(is_even);
|
||||
assert Some(2u).all(is_even);
|
||||
assert None.all(is_even);
|
||||
assert !iter::all(&Some(1u), is_even);
|
||||
assert iter::all(&Some(2u), is_even);
|
||||
assert iter::all(&None::<uint>, is_even);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub fn main() {
|
|||
assert [1u, 2u].any(is_even);
|
||||
assert ![].any(is_even);
|
||||
|
||||
assert !Some(1).any(is_even);
|
||||
assert Some(2).any(is_even);
|
||||
assert !None.any(is_even);
|
||||
assert !iter::any(&Some(1u), is_even);
|
||||
assert iter::any(&Some(2u), is_even);
|
||||
assert !iter::any(&None::<uint>, is_even);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ pub fn main() {
|
|||
assert [22u, 1u, 3u].contains(&22u) == true;
|
||||
assert [1u, 22u, 3u].contains(&22u) == true;
|
||||
assert [1u, 3u, 22u].contains(&22u) == true;
|
||||
assert None.contains(&22u) == false;
|
||||
assert Some(1u).contains(&22u) == false;
|
||||
assert Some(22u).contains(&22u) == true;
|
||||
assert iter::contains(&None::<uint>, &22u) == false;
|
||||
assert iter::contains(&Some(1u), &22u) == false;
|
||||
assert iter::contains(&Some(22u), &22u) == true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub fn main() {
|
|||
assert [1u, 3u].count(&22u) == 0u;
|
||||
assert [22u, 1u, 3u].count(&22u) == 1u;
|
||||
assert [22u, 1u, 22u].count(&22u) == 2u;
|
||||
assert None.count(&22u) == 0u;
|
||||
assert Some(1u).count(&22u) == 0u;
|
||||
assert Some(22u).count(&22u) == 1u;
|
||||
assert iter::count(&None::<uint>, &22u) == 0u;
|
||||
assert iter::count(&Some(1u), &22u) == 0u;
|
||||
assert iter::count(&Some(22u), &22u) == 1u;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,12 @@ pub fn main() {
|
|||
}
|
||||
assert c == 5u;
|
||||
|
||||
for None::<uint>.eachi |i, v| { fail!(); }
|
||||
for iter::eachi(&None::<uint>) |i, v| { fail!(); }
|
||||
|
||||
let mut c = 0u;
|
||||
for Some(1u).eachi |i, v| {
|
||||
for iter::eachi(&Some(1u)) |i, v| {
|
||||
assert (i + 1u) == *v;
|
||||
c += 1u;
|
||||
}
|
||||
assert c == 1u;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ fn is_even(x: &uint) -> bool { (*x % 2) == 0 }
|
|||
pub fn main() {
|
||||
assert [1, 3].filter_to_vec(is_even) == ~[];
|
||||
assert [1, 2, 3].filter_to_vec(is_even) == ~[2];
|
||||
assert None.filter_to_vec(is_even) == ~[];
|
||||
assert Some(1).filter_to_vec(is_even) == ~[];
|
||||
assert Some(2).filter_to_vec(is_even) == ~[2];
|
||||
assert iter::filter_to_vec(&None::<uint>, is_even) == ~[];
|
||||
assert iter::filter_to_vec(&Some(1u), is_even) == ~[];
|
||||
assert iter::filter_to_vec(&Some(2u), is_even) == ~[2];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@ fn incd_if_even(x: &uint) -> Option<uint> {
|
|||
pub fn main() {
|
||||
assert (~[1u, 3u]).flat_map_to_vec(repeat) == ~[1u, 1u, 3u, 3u];
|
||||
assert (~[]).flat_map_to_vec(repeat) == ~[];
|
||||
assert None.flat_map_to_vec(repeat) == ~[];
|
||||
assert Some(1u).flat_map_to_vec(repeat) == ~[1u, 1u];
|
||||
assert Some(2u).flat_map_to_vec(repeat) == ~[2u, 2u];
|
||||
assert iter::flat_map_to_vec(&None::<uint>, repeat) == ~[];
|
||||
assert iter::flat_map_to_vec(&Some(1u), repeat) == ~[1u, 1u];
|
||||
assert iter::flat_map_to_vec(&Some(2u), repeat) == ~[2u, 2u];
|
||||
|
||||
assert (~[1u, 2u, 5u]).flat_map_to_vec(incd_if_even) == ~[3u];
|
||||
assert (~[]).flat_map_to_vec(incd_if_even) == ~[];
|
||||
assert None.flat_map_to_vec(incd_if_even) == ~[];
|
||||
assert Some(1u).flat_map_to_vec(incd_if_even) == ~[];
|
||||
assert Some(2u).flat_map_to_vec(incd_if_even) == ~[3u];
|
||||
assert iter::flat_map_to_vec(&None::<uint>, incd_if_even) == ~[];
|
||||
assert iter::flat_map_to_vec(&Some(1u), incd_if_even) == ~[];
|
||||
assert iter::flat_map_to_vec(&Some(2u), incd_if_even) == ~[3u];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ fn add(x: &float, y: &uint) -> float { *x + ((*y) as float) }
|
|||
pub fn main() {
|
||||
assert [1u, 3u].foldl(20f, add) == 24f;
|
||||
assert [].foldl(20f, add) == 20f;
|
||||
assert None.foldl(20f, add) == 20f;
|
||||
assert Some(1u).foldl(20f, add) == 21f;
|
||||
assert Some(2u).foldl(20f, add) == 22f;
|
||||
assert iter::foldl(&None::<uint>, 20f, add) == 20f;
|
||||
assert iter::foldl(&Some(1u), 20f, add) == 21f;
|
||||
assert iter::foldl(&Some(2u), 20f, add) == 22f;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ fn inc(x: &uint) -> uint { *x + 1 }
|
|||
pub fn main() {
|
||||
assert [1, 3].map_to_vec(inc) == ~[2, 4];
|
||||
assert [1, 2, 3].map_to_vec(inc) == ~[2, 3, 4];
|
||||
assert None.map_to_vec(inc) == ~[];
|
||||
assert Some(1).map_to_vec(inc) == ~[2];
|
||||
assert Some(2).map_to_vec(inc) == ~[3];
|
||||
assert iter::map_to_vec(&None::<uint>, inc) == ~[];
|
||||
assert iter::map_to_vec(&Some(1u), inc) == ~[2];
|
||||
assert iter::map_to_vec(&Some(2u), inc) == ~[3];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ fn is_even(&&x: uint) -> bool { (x % 2u) == 0u }
|
|||
pub fn main() {
|
||||
assert [1u, 3u].min() == 1u;
|
||||
assert [3u, 1u].min() == 1u;
|
||||
assert Some(1u).min() == 1u;
|
||||
assert iter::min(&Some(1u)) == 1u;
|
||||
|
||||
assert [1u, 3u].max() == 3u;
|
||||
assert [3u, 1u].max() == 3u;
|
||||
assert Some(3u).max() == 3u;
|
||||
assert iter::max(&Some(3u)) == 3u;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub fn main() {
|
|||
assert [1u, 3u].to_vec() == ~[1u, 3u];
|
||||
let e: ~[uint] = ~[];
|
||||
assert e.to_vec() == ~[];
|
||||
assert None::<uint>.to_vec() == ~[];
|
||||
assert Some(1u).to_vec() == ~[1u];
|
||||
assert Some(2u).to_vec() == ~[2u];
|
||||
assert iter::to_vec(&None::<uint>) == ~[];
|
||||
assert iter::to_vec(&Some(1u)) == ~[1u];
|
||||
assert iter::to_vec(&Some(2u)) == ~[2u];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue