// except according to those terms.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use core::os;
use core::run;
err_fd: None
});
- for input.each |input| {
+ for input.iter().advance |input| {
proc.input().write_str(*input);
}
let output = proc.finish_with_output();
fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
let mapped = map_slices(xs, || {
let f = fn_factory();
- let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any(f);
+ let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any_(f);
result
});
- mapped.iter().any(|&x| x)
+ mapped.iter().any_(|&x| x)
}
b = y.next();
}
}
- return b.each(|&x| f(x)) && y.advance(f);
+ b.iter().advance(|&x| f(x)) && y.advance(f)
}
/// Visit the values (in-order) representing the intersection
a = x.next();
}
}
- return b.each(|&x| f(x)) && y.advance(f);
+ b.iter().advance(|&x| f(x)) && y.advance(f)
}
}
fn each<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
f: &fn(&'r K, &'r V) -> bool) -> bool {
- node.each(|x| each(&x.left, f) && f(&x.key, &x.value) &&
- each(&x.right, f))
+ node.iter().advance(|x| each(&x.left, f) && f(&x.key, &x.value) &&
+ each(&x.right, f))
}
fn each_reverse<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
f: &fn(&'r K, &'r V) -> bool) -> bool {
- node.each(|x| each_reverse(&x.right, f) && f(&x.key, &x.value) &&
- each_reverse(&x.left, f))
+ node.iter().advance(|x| each_reverse(&x.right, f) && f(&x.key, &x.value) &&
+ each_reverse(&x.left, f))
}
fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
fn heir_swap<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>,
child: &mut Option<~TreeNode<K, V>>) {
// *could* be done without recursion, but it won't borrow check
- for child.each_mut |x| {
+ for child.mut_iter().advance |x| {
if x.right.is_some() {
heir_swap(node, &mut x.right);
} else {
save.level -= 1;
if right_level > save.level {
- for save.right.each_mut |x| { x.level = save.level }
+ for save.right.mut_iter().advance |x| { x.level = save.level }
}
skew(save);
- for save.right.each_mut |right| {
+ for save.right.mut_iter().advance |right| {
skew(right);
- for right.right.each_mut |x| { skew(x) }
+ for right.right.mut_iter().advance |x| { skew(x) }
}
split(save);
- for save.right.each_mut |x| { split(x) }
+ for save.right.mut_iter().advance |x| { split(x) }
}
return ret;
let mut n = 0;
for m.each |x| {
+ println(fmt!("%?", x));
assert_eq!(*x, n);
n += 1
}
extern mod rustc;
use core::prelude::*;
+use core::iterator::IteratorUtil;
use core::io;
use core::os;
let args = os_args.tail();
if !args.is_empty() {
- for find_cmd(*args.head()).each |command| {
+ let r = find_cmd(*args.head());
+ for r.iter().advance |command| {
let result = do_command(command, args.tail());
match result {
Valid(exit_code) => unsafe { exit(exit_code.to_i32()) },
use middle;
use util::ppaux::ty_to_str;
+use core::iterator::IteratorUtil;
use core::hash::HashUtil;
use core::hashmap::HashMap;
use core::int;
ebml_w: &mut writer::Encoder,
it: @ast::item) {
let opt_rp = ecx.tcx.region_paramd_items.find(&it.id);
- for opt_rp.each |rp| {
+ for opt_rp.iter().advance |rp| {
ebml_w.start_tag(tag_region_param);
rp.encode(ebml_w);
ebml_w.end_tag();
fn encode_transformed_self_ty(ecx: @EncodeContext,
ebml_w: &mut writer::Encoder,
opt_typ: Option<ty::t>) {
- for opt_typ.each |&typ| {
+ for opt_typ.iter().advance |&typ| {
ebml_w.start_tag(tag_item_method_transformed_self_ty);
write_type(ecx, ebml_w, typ);
ebml_w.end_tag();
ebml_w.writer.write(str::to_bytes(def_to_str(method_def_id)));
ebml_w.end_tag();
}
- for opt_trait.each |ast_trait_ref| {
+ for opt_trait.iter().advance |ast_trait_ref| {
let trait_ref = ty::node_id_to_trait_ref(ecx.tcx, ast_trait_ref.ref_id);
encode_trait_ref(ebml_w, ecx, trait_ref, tag_item_trait_ref);
}
use middle;
use util::ppaux::ty_to_str;
+use core::iterator::IteratorUtil;
use core::at_vec;
use core::uint;
use extra::ebml::reader;
debug!("Encoding side tables for id %d", id);
- for tcx.def_map.find(&id).each |def| {
- do ebml_w.tag(c::tag_table_def) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- (*def).encode(ebml_w)
+ {
+ let r = tcx.def_map.find(&id);
+ for r.iter().advance |def| {
+ do ebml_w.tag(c::tag_table_def) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ (*def).encode(ebml_w)
+ }
}
}
}
- for tcx.node_types.find(&(id as uint)).each |&ty| {
- do ebml_w.tag(c::tag_table_node_type) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- ebml_w.emit_ty(ecx, *ty);
+ {
+ let r = tcx.node_types.find(&(id as uint));
+ for r.iter().advance |&ty| {
+ do ebml_w.tag(c::tag_table_node_type) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ ebml_w.emit_ty(ecx, *ty);
+ }
}
}
}
- for tcx.node_type_substs.find(&id).each |tys| {
- do ebml_w.tag(c::tag_table_node_type_subst) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- ebml_w.emit_tys(ecx, **tys)
+ {
+ let r = tcx.node_type_substs.find(&id);
+ for r.iter().advance |tys| {
+ do ebml_w.tag(c::tag_table_node_type_subst) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ ebml_w.emit_tys(ecx, **tys)
+ }
}
}
}
- for tcx.freevars.find(&id).each |&fv| {
- do ebml_w.tag(c::tag_table_freevars) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- do ebml_w.emit_from_vec(**fv) |ebml_w, fv_entry| {
- encode_freevar_entry(ebml_w, *fv_entry)
+ {
+ let r = tcx.freevars.find(&id);
+ for r.iter().advance |&fv| {
+ do ebml_w.tag(c::tag_table_freevars) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ do ebml_w.emit_from_vec(**fv) |ebml_w, fv_entry| {
+ encode_freevar_entry(ebml_w, *fv_entry)
+ }
}
}
}
}
let lid = ast::def_id { crate: ast::local_crate, node: id };
- for tcx.tcache.find(&lid).each |&tpbt| {
- do ebml_w.tag(c::tag_table_tcache) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- ebml_w.emit_tpbt(ecx, *tpbt);
+ {
+ let r = tcx.tcache.find(&lid);
+ for r.iter().advance |&tpbt| {
+ do ebml_w.tag(c::tag_table_tcache) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ ebml_w.emit_tpbt(ecx, *tpbt);
+ }
}
}
}
- for tcx.ty_param_defs.find(&id).each |&type_param_def| {
- do ebml_w.tag(c::tag_table_param_defs) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- ebml_w.emit_type_param_def(ecx, type_param_def)
+ {
+ let r = tcx.ty_param_defs.find(&id);
+ for r.iter().advance |&type_param_def| {
+ do ebml_w.tag(c::tag_table_param_defs) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ ebml_w.emit_type_param_def(ecx, type_param_def)
+ }
}
}
}
- for maps.method_map.find(&id).each |&mme| {
- do ebml_w.tag(c::tag_table_method_map) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- encode_method_map_entry(ecx, ebml_w, *mme)
+ {
+ let r = maps.method_map.find(&id);
+ for r.iter().advance |&mme| {
+ do ebml_w.tag(c::tag_table_method_map) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ encode_method_map_entry(ecx, ebml_w, *mme)
+ }
}
}
}
- for maps.vtable_map.find(&id).each |&dr| {
- do ebml_w.tag(c::tag_table_vtable_map) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- encode_vtable_res(ecx, ebml_w, *dr);
+ {
+ let r = maps.vtable_map.find(&id);
+ for r.iter().advance |&dr| {
+ do ebml_w.tag(c::tag_table_vtable_map) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ encode_vtable_res(ecx, ebml_w, *dr);
+ }
}
}
}
- for tcx.adjustments.find(&id).each |adj| {
- do ebml_w.tag(c::tag_table_adjustments) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- (**adj).encode(ebml_w)
+ {
+ let r = tcx.adjustments.find(&id);
+ for r.iter().advance |adj| {
+ do ebml_w.tag(c::tag_table_adjustments) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ (**adj).encode(ebml_w)
+ }
}
}
}
}
}
- for maps.capture_map.find(&id).each |&cap_vars| {
- do ebml_w.tag(c::tag_table_capture_map) |ebml_w| {
- ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) |ebml_w| {
- do ebml_w.emit_from_vec(*cap_vars) |ebml_w, cap_var| {
- cap_var.encode(ebml_w);
+ {
+ let r = maps.capture_map.find(&id);
+ for r.iter().advance |&cap_vars| {
+ do ebml_w.tag(c::tag_table_capture_map) |ebml_w| {
+ ebml_w.id(id);
+ do ebml_w.tag(c::tag_table_val) |ebml_w| {
+ do ebml_w.emit_from_vec(*cap_vars) |ebml_w, cap_var| {
+ cap_var.encode(ebml_w);
+ }
}
}
}
// 4. moves do not affect things loaned out in any way
use core::prelude::*;
+use core::iterator::IteratorUtil;
use core::hashmap::HashSet;
use core::uint;
// FIXME(#4384) inadequare if/when we permit `move a.b`
// check for a conflicting loan:
- for opt_loan_path(cmt).each |&lp| {
+ let r = opt_loan_path(cmt);
+ for r.iter().advance |&lp| {
for self.each_in_scope_restriction(cmt.id, lp) |loan, _| {
// Any restriction prevents moves.
return MoveWhileBorrowed(lp, loan.loan_path, loan.span);
}
}
- return MoveOk;
+ MoveOk
}
pub fn check_call(&mut self,
if !this.move_data.is_assignee(expr.id) {
let cmt = this.bccx.cat_expr_unadjusted(expr);
debug!("path cmt=%s", cmt.repr(this.tcx()));
- for opt_loan_path(cmt).each |&lp| {
- this.check_if_path_is_moved(expr.id, expr.span,
- MovedInUse, lp);
+ let r = opt_loan_path(cmt);
+ for r.iter().advance |&lp| {
+ this.check_if_path_is_moved(expr.id, expr.span, MovedInUse, lp);
}
}
}
// sure that all of these loans are honored.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use middle::borrowck::*;
use middle::borrowck::move_data::MoveData;
this.id_range.add(ex.id);
- for ex.get_callee_id().each |callee_id| {
- this.id_range.add(*callee_id);
+ {
+ let r = ex.get_callee_id();
+ for r.iter().advance |callee_id| {
+ this.id_range.add(*callee_id);
+ }
}
// If this expression is borrowed, have to ensure it remains valid:
- for tcx.adjustments.find(&ex.id).each |&adjustments| {
- this.guarantee_adjustments(ex, *adjustments);
+ {
+ let r = tcx.adjustments.find(&ex.id);
+ for r.iter().advance |&adjustments| {
+ this.guarantee_adjustments(ex, *adjustments);
+ }
}
// If this expression is a move, gather it:
*/
use core::prelude::*;
+use core::iterator::IteratorUtil;
use core::hashmap::{HashMap, HashSet};
use core::uint;
loop;
}
- for opt_loan_path_index.each |&loan_path_index| {
+ for opt_loan_path_index.iter().advance |&loan_path_index| {
for self.move_data.each_base_path(moved_path) |p| {
if p == loan_path_index {
// Scenario 3: some extension of `loan_path`
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use core::iterator::IteratorUtil;
use core::prelude::*;
use driver::session::Session;
}
item_enum(ref enum_definition, _) => {
for (*enum_definition).variants.each |var| {
- for var.node.disr_expr.each |ex| {
+ for var.node.disr_expr.iter().advance |ex| {
(v.visit_expr)(*ex, true, v);
}
}
ty::ty_enum(eid, _) => {
let mut found = ~[];
for m.each |r| {
- for pat_ctor_id(cx, r[0]).each |id| {
+ let r = pat_ctor_id(cx, r[0]);
+ for r.iter().advance |id| {
if !vec::contains(found, id) {
found.push(/*bad*/copy *id);
}
opt_expr: Option<@ast::expr>,
in_out: &mut [uint],
loop_scopes: &mut ~[LoopScope]) {
- for opt_expr.each |&expr| {
+ for opt_expr.iter().advance |&expr| {
self.walk_expr(expr, in_out, loop_scopes);
}
}
Some(callee_id) => callee_id,
None => e.id,
};
- for cx.tcx.node_type_substs.find(&type_parameter_id).each |ts| {
- let type_param_defs = match e.node {
- expr_path(_) => {
- let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&e.id));
- ty::lookup_item_type(cx.tcx, did).generics.type_param_defs
- }
- _ => {
- // Type substitutions should only occur on paths and
- // method calls, so this needs to be a method call.
-
- // Even though the callee_id may have been the id with
- // node_type_substs, e.id is correct here.
- ty::method_call_type_param_defs(cx.tcx, cx.method_map, e.id).expect(
- "non path/method call expr has type substs??")
- }
- };
- if ts.len() != type_param_defs.len() {
- // Fail earlier to make debugging easier
- fail!("internal error: in kind::check_expr, length \
- mismatch between actual and declared bounds: actual = \
- %s, declared = %s",
- ts.repr(cx.tcx),
- type_param_defs.repr(cx.tcx));
- }
- for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
- check_bounds(cx, type_parameter_id, e.span, ty, type_param_def)
+ {
+ let r = cx.tcx.node_type_substs.find(&type_parameter_id);
+ for r.iter().advance |ts| {
+ let type_param_defs = match e.node {
+ expr_path(_) => {
+ let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&e.id));
+ ty::lookup_item_type(cx.tcx, did).generics.type_param_defs
+ }
+ _ => {
+ // Type substitutions should only occur on paths and
+ // method calls, so this needs to be a method call.
+
+ // Even though the callee_id may have been the id with
+ // node_type_substs, e.id is correct here.
+ ty::method_call_type_param_defs(cx.tcx, cx.method_map, e.id).expect(
+ "non path/method call expr has type substs??")
+ }
+ };
+ if ts.len() != type_param_defs.len() {
+ // Fail earlier to make debugging easier
+ fail!("internal error: in kind::check_expr, length \
+ mismatch between actual and declared bounds: actual = \
+ %s, declared = %s",
+ ts.repr(cx.tcx),
+ type_param_defs.repr(cx.tcx));
+ }
+ for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
+ check_bounds(cx, type_parameter_id, e.span, ty, type_param_def)
+ }
}
}
fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
match aty.node {
ty_path(_, id) => {
- for cx.tcx.node_type_substs.find(&id).each |ts| {
- let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
- let type_param_defs =
- ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
- for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
- check_bounds(cx, aty.id, aty.span, ty, type_param_def)
- }
- }
+ let r = cx.tcx.node_type_substs.find(&id);
+ for r.iter().advance |ts| {
+ let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
+ let type_param_defs =
+ ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
+ for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
+ check_bounds(cx, aty.id, aty.span, ty, type_param_def)
+ }
+ }
}
_ => {}
}
use middle::pat_util;
use util::ppaux::{ty_to_str};
+use core::iterator::IteratorUtil;
use core::char;
use core::cmp;
use core::hashmap::HashMap;
allow => fail!(),
}
- for note.each |&span| {
+ for note.iter().advance |&span| {
self.tcx.sess.span_note(span, "lint level defined here");
}
}
use core::cast::transmute;
use core::hashmap::HashMap;
use core::io;
-use core::old_iter;
use core::to_str;
use core::uint;
use core::vec;
opt_expr: Option<@expr>,
succ: LiveNode)
-> LiveNode {
- do old_iter::foldl(&opt_expr, succ) |succ, expr| {
- self.propagate_through_expr(*expr, *succ)
+ do opt_expr.iter().fold(succ) |succ, expr| {
+ self.propagate_through_expr(*expr, succ)
}
}
var: Variable)
-> bool {
if !self.used_on_entry(ln, var) {
- for self.should_warn(var).each |name| {
+ let r = self.should_warn(var);
+ for r.iter().advance |name| {
// annoying: for parameters in funcs like `fn(x: int)
// {ret}`, there is only one node, so asking about
fmt!("unused variable: `%s`", **name));
}
}
- return true;
+ true
+ } else {
+ false
}
- return false;
}
pub fn warn_about_dead_assign(&self,
ln: LiveNode,
var: Variable) {
if self.live_on_exit(ln, var).is_none() {
- for self.should_warn(var).each |name| {
+ let r = self.should_warn(var);
+ for r.iter().advance |name| {
self.tcx.sess.add_lint(dead_assignment, id, sp,
fmt!("value assigned to `%s` is never read", **name));
}
*/
use core::prelude::*;
+use core::iterator::IteratorUtil;
use middle::ty;
use middle::typeck;
for before.each |&before_pat| {
self.cat_pattern(elt_cmt, before_pat, op);
}
- for slice.each |&slice_pat| {
+ for slice.iter().advance |&slice_pat| {
let slice_ty = self.pat_ty(slice_pat);
let slice_cmt = self.cat_rvalue(pat, slice_ty);
self.cat_pattern(slice_cmt, slice_pat, op);
*/
use core::prelude::*;
+use core::iterator::IteratorUtil;
use middle::pat_util::{pat_bindings};
use middle::freevars;
(visitor.visit_stmt)(*stmt, *self, visitor);
}
- for blk.node.expr.each |tail_expr| {
+ for blk.node.expr.iter().advance |tail_expr| {
self.consume_expr(*tail_expr, visitor);
}
}
match comp_mode {
Move => {
let def = self.tcx.def_map.get_copy(&expr.id);
- for moved_variable_node_id_from_def(def).each |&id| {
+ let r = moved_variable_node_id_from_def(def);
+ for r.iter().advance |&id| {
self.move_maps.moved_variables_set.insert(id);
}
}
self.consume_expr(field.node.expr, visitor);
}
- for opt_with.each |with_expr| {
+ for opt_with.iter().advance |with_expr| {
// If there are any fields whose type is move-by-default,
// then `with` is consumed, otherwise it is only read
let with_ty = ty::expr_ty(self.tcx, *with_expr);
expr_if(cond_expr, ref then_blk, opt_else_expr) => {
self.consume_expr(cond_expr, visitor);
self.consume_block(then_blk, visitor);
- for opt_else_expr.each |else_expr| {
+ for opt_else_expr.iter().advance |else_expr| {
self.consume_expr(*else_expr, visitor);
}
}
}
expr_ret(ref opt_expr) => {
- for opt_expr.each |expr| {
+ for opt_expr.iter().advance |expr| {
self.consume_expr(*expr, visitor);
}
}
}
pub fn consume_arm(&self, arm: &arm, visitor: vt<VisitContext>) {
- for arm.pats.each |pat| {
+ for arm.pats.iter().advance |pat| {
self.use_pat(*pat);
}
- for arm.guard.each |guard| {
+ for arm.guard.iter().advance |guard| {
self.consume_expr(*guard, visitor);
}
use middle::ty::{rv_contravariant, FreeRegion};
use middle::ty;
+use core::iterator::IteratorUtil;
use core::hashmap::{HashMap, HashSet};
use syntax::ast_map;
use syntax::codemap::span;
pub fn parent_to_expr(cx: Context, child_id: ast::node_id, sp: span) {
debug!("region::parent_to_expr(span=%?)",
cx.sess.codemap.span_to_str(sp));
- for cx.parent.each |parent_id| {
+ for cx.parent.iter().advance |parent_id| {
cx.region_maps.record_parent(child_id, *parent_id);
}
}
fmt!("duplicate definition of %s `%s`",
namespace_to_str(ns),
*self.session.str_of(name)));
- for child.span_for_namespace(ns).each |sp| {
- self.session.span_note(*sp,
- fmt!("first definition of %s %s here:",
- namespace_to_str(ns),
- *self.session.str_of(name)));
+ {
+ let r = child.span_for_namespace(ns);
+ for r.iter().advance |sp| {
+ self.session.span_note(*sp,
+ fmt!("first definition of %s %s here:",
+ namespace_to_str(ns),
+ *self.session.str_of(name)));
+ }
}
}
return (child, new_parent);
// then resolve the ty params
item_enum(ref enum_def, ref generics) => {
for (*enum_def).variants.each() |variant| {
- for variant.node.disr_expr.each |dis_expr| {
+ for variant.node.disr_expr.iter().advance |dis_expr| {
// resolve the discriminator expr
// as a constant
self.with_constant_rib(|| {
// Record the current set of trait references.
let mut new_trait_refs = ~[];
- for self.def_map.find(&trait_reference.ref_id).each |&def| {
- new_trait_refs.push(def_id_of_def(*def));
+ {
+ let r = self.def_map.find(&trait_reference.ref_id);
+ for r.iter().advance |&def| {
+ new_trait_refs.push(def_id_of_def(*def));
+ }
}
original_trait_refs = Some(util::replace(
&mut self.current_trait_refs,
pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
let ccx = bcx.ccx();
fn add_to_set(tcx: ty::ctxt, set: &mut ~[Opt], val: Opt) {
- if set.iter().any(|l| opt_eq(tcx, l, &val)) {return;}
+ if set.iter().any_(|l| opt_eq(tcx, l, &val)) {return;}
set.push(val);
}
fn extend(idents: &mut ~[ast::ident], field_pats: &[ast::field_pat]) {
for field_pats.each |field_pat| {
let field_ident = field_pat.ident;
- if !idents.iter().any(|x| *x == field_ident) {
+ if !idents.iter().any_(|x| *x == field_ident) {
idents.push(field_ident);
}
}
m: &[@Match],
col: uint)
-> bool {
- do m.iter().any |br| {
+ do m.iter().any_ |br| {
let pat_id = br.pats[col].id;
let key = root_map_key {id: pat_id, derefs: 0u };
bcx.ccx().maps.root_map.contains_key(&key)
// matches may be wildcards like _ or identifiers).
macro_rules! any_pat (
($m:expr, $pattern:pat) => (
- do ($m).iter().any |br| {
+ do ($m).iter().any_ |br| {
match br.pats[col].node {
$pattern => true,
_ => false
}
pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool {
- do m.iter().any |br| {
+ do m.iter().any_ |br| {
let pat = br.pats[col];
match pat.node {
ast::pat_enum(_, Some(_)) => {
var(_, repr) => {
let (the_kind, val_opt) = adt::trans_switch(bcx, repr, val);
kind = the_kind;
- for val_opt.each |&tval| { test_val = tval; }
+ for val_opt.iter().advance |&tval| { test_val = tval; }
}
lit(_) => {
let pty = node_id_type(bcx, pat_id);
}
}
- for inner.each |inner_pat| {
+ for inner.iter().advance |inner_pat| {
bcx = bind_irrefutable_pat(
bcx, *inner_pat, val, true, binding_mode);
}
repr,
vinfo.disr_val,
val);
- for sub_pats.each |sub_pat| {
+ for sub_pats.iter().advance |sub_pat| {
for args.vals.eachi |i, argval| {
bcx = bind_irrefutable_pat(bcx,
sub_pat[i],
is_lpad,
opt_node_info,
cx);
- for parent.each |cx| {
+ for parent.iter().advance |cx| {
if cx.unreachable { Unreachable(bcx); }
};
bcx
block_scope(inf) if !inf.empty_cleanups() => {
let (sub_cx, inf_cleanups) = {
let inf = &mut *inf; // FIXME(#5074) workaround stage0
- for vec::find((*inf).cleanup_paths,
- |cp| cp.target == leave).each |cp| {
- Br(bcx, cp.dest);
- return;
+ {
+ let r = vec::find((*inf).cleanup_paths, |cp| cp.target == leave);
+ for r.iter().advance |cp| {
+ Br(bcx, cp.dest);
+ return;
+ }
}
let sub_cx = sub_block(bcx, "cleanup");
Br(bcx, sub_cx.llbb);
};
let val = alloc_ty(cx, t);
if cx.sess().opts.debuginfo {
- for simple_name.each |name| {
+ for simple_name.iter().advance |name| {
str::as_c_str(*cx.ccx().sess.str_of(*name), |buf| {
unsafe {
llvm::LLVMSetValueName(val, buf)
param_substs: Option<@param_substs>,
sp: Option<span>)
-> fn_ctxt {
- for param_substs.each |p| { p.validate(); }
+ for param_substs.iter().advance |p| { p.validate(); }
debug!("new_fn_ctxt_w_id(path=%s, id=%?, impl_id=%?, \
param_substs=%s)",
// closure.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use back::abi;
use driver::session;
} 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| {
- for (copy bcx.fcx.loop_ret).each |&(flagptr, _)| {
- Store(bcx, C_bool(true), flagptr);
- Store(bcx, C_bool(false), bcx.fcx.llretptr.get());
+ {
+ let r = (copy bcx.fcx.loop_ret);
+ for r.iter().advance |&(flagptr, _)| {
+ Store(bcx, C_bool(true), flagptr);
+ Store(bcx, C_bool(false), bcx.fcx.llretptr.get());
+ }
}
base::cleanup_and_leave(bcx, None, Some(bcx.fcx.llreturn));
Unreachable(bcx);
// except according to those terms.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use back::abi;
use back::link::{mangle_internal_name_by_path_and_seq};
// If this is a `for` loop body, add two special environment
// variables:
- for include_ret_handle.each |flagptr| {
+ for include_ret_handle.iter().advance |flagptr| {
// Flag indicating we have returned (a by-ref bool):
let flag_datum = Datum {val: *flagptr, ty: ty::mk_bool(),
mode: ByRef(ZeroMem)};
//! Code that is useful in various trans modules.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use back::{abi, upcall};
use driver::session;
impl param_substs {
pub fn validate(&self) {
for self.tys.each |t| { assert!(!ty::type_needs_infer(*t)); }
- for self.self_ty.each |t| { assert!(!ty::type_needs_infer(*t)); }
+ for self.self_ty.iter().advance |t| { assert!(!ty::type_needs_infer(*t)); }
}
}
clean_temp(v, _, _) if v == val => true,
_ => false
});
- for cleanup_pos.each |i| {
+ for cleanup_pos.iter().advance |i| {
scope_info.cleanups =
vec::append(vec::slice(scope_info.cleanups, 0u, *i).to_vec(),
vec::slice(scope_info.cleanups,
use util::common::indenter;
use util::ppaux::Repr;
+use core::iterator::IteratorUtil;
use core::cast::transmute;
use core::hashmap::HashMap;
use core::vec;
for fields.each |&(_i, e)| {
bcx = trans_into(bcx, e, Ignore);
}
- for optbase.each |sbi| {
+ for optbase.iter().advance |sbi| {
bcx = trans_into(bcx, sbi.expr, Ignore);
}
return bcx;
add_clean_temp_mem(bcx, dest, e_ty);
temp_cleanups.push(dest);
}
- for optbase.each |base| {
+ for optbase.iter().advance |base| {
// FIXME #6573: is it sound to use the destination's repr on the base?
// And, would it ever be reasonable to be here with discr != 0?
let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base.expr));
- for base.fields.each |&(i, t)| {
+ for base.fields.iter().advance |&(i, t)| {
let datum = do base_datum.get_element(bcx, t, ZeroMem) |srcval| {
adt::trans_field_ptr(bcx, repr, srcval, discr, i)
};
let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len());
let hash_id = make_mono_id(ccx, fn_id, substs, vtables, impl_did_opt,
Some(param_uses));
- if hash_id.params.iter().any(
+ if hash_id.params.iter().any_(
|p| match *p { mono_precise(_, _) => false, _ => true }) {
must_cast = true;
}
// reachable as well.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use middle::resolve;
use middle::ty;
}
}
item_struct(ref struct_def, _) => {
- for struct_def.ctor_id.each |&ctor_id| {
+ for struct_def.ctor_id.iter().advance |&ctor_id| {
let cx = &mut *cx; // FIXME(#6269) reborrow @mut to &mut
cx.rmap.insert(ctor_id);
}
pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
let mut opt_static_did = None;
- for cx.ccx.maps.method_map.find(&e_id).each |mth| {
- match mth.origin {
- typeck::method_static(did) => {
- opt_static_did = Some(did);
- }
- typeck::method_param(typeck::method_param {
- param_num: param,
- _
- }) => {
- cx.uses[param] |= use_tydesc;
- }
- typeck::method_trait(*) | typeck::method_self(*)
- | typeck::method_super(*) => (),
+ {
+ let r = cx.ccx.maps.method_map.find(&e_id);
+ for r.iter().advance |mth| {
+ match mth.origin {
+ typeck::method_static(did) => {
+ opt_static_did = Some(did);
+ }
+ typeck::method_param(typeck::method_param {
+ param_num: param,
+ _
+ }) => {
+ cx.uses[param] |= use_tydesc;
+ }
+ typeck::method_trait(*) | typeck::method_self(*)
+ | typeck::method_super(*) => (),
+ }
}
}
// above because the recursive call to `type_needs` can trigger
// inlining and hence can cause `method_map` and
// `node_type_substs` to be modified.
- for opt_static_did.each |&did| {
- for cx.ccx.tcx.node_type_substs.find_copy(&callee_id).each |ts| {
- let type_uses = type_uses_for(cx.ccx, did, ts.len());
- for type_uses.iter().zip(ts.iter()).advance |(uses, subst)| {
- type_needs(cx, *uses, *subst)
+ for opt_static_did.iter().advance |&did| {
+ {
+ let r = cx.ccx.tcx.node_type_substs.find_copy(&callee_id);
+ for r.iter().advance |ts| {
+ let type_uses = type_uses_for(cx.ccx, did, ts.len());
+ for type_uses.iter().zip(ts.iter()).advance |(uses, subst)| {
+ type_needs(cx, *uses, *subst)
+ }
}
}
}
}
expr_path(_) | expr_self => {
let opt_ts = cx.ccx.tcx.node_type_substs.find_copy(&e.id);
- for opt_ts.each |ts| {
+ for opt_ts.iter().advance |ts| {
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get_copy(&e.id));
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
for uses_for_ts.iter().zip(ts.iter()).advance |(uses, subst)| {
},
visit_block: |b, cx, v| {
visit::visit_block(b, cx, v);
- for b.node.expr.each |e| {
+ for b.node.expr.iter().advance |e| {
node_type_needs(cx, use_repr, e.id);
}
},
fn sflags(substs: &substs) -> uint {
let mut f = 0u;
for substs.tps.each |tt| { f |= get(*tt).flags; }
- for substs.self_r.each |r| { f |= rflags(*r) }
+ for substs.self_r.iter().advance |r| { f |= rflags(*r) }
return f;
}
match &st {
}
pub fn trait_ref_contains_error(tref: &ty::TraitRef) -> bool {
- tref.substs.self_ty.any(|&t| type_is_error(t)) ||
- tref.substs.tps.any(|&t| type_is_error(t))
+ tref.substs.self_ty.iter().any_(|&t| type_is_error(t)) ||
+ tref.substs.tps.iter().any_(|&t| type_is_error(t))
}
pub fn type_is_ty_var(ty: t) -> bool {
ty_struct(did, ref substs) => {
seen.push(did);
let fields = struct_fields(cx, did, substs);
- let r = fields.iter().any(|f| type_requires(cx, seen, r_ty, f.mt.ty));
+ let r = fields.iter().any_(|f| type_requires(cx, seen, r_ty, f.mt.ty));
seen.pop();
r
}
seen.push(did);
let vs = enum_variants(cx, did);
let r = !vs.is_empty() && do vs.iter().all |variant| {
- do variant.args.iter().any |aty| {
+ do variant.args.iter().any_ |aty| {
let sty = subst(cx, substs, *aty);
type_requires(cx, seen, r_ty, sty)
}
}
if !error_happened {
- for subpats.each |pats| {
+ for subpats.iter().advance |pats| {
for pats.iter().zip(arg_types.iter()).advance |(subpat, arg_ty)| {
check_pat(pcx, *subpat, *arg_ty);
}
}
if error_happened {
- for subpats.each |pats| {
+ for subpats.iter().advance |pats| {
for pats.each |pat| {
check_pat(pcx, *pat, ty::mk_err());
}
for before.each |&elt| {
check_pat(pcx, elt, ty::mk_err());
}
- for slice.each |&elt| {
+ for slice.iter().advance |&elt| {
check_pat(pcx, elt, ty::mk_err());
}
for after.each |&elt| {
// candidates.
let trait_map: &mut resolve::TraitMap = &mut self.fcx.ccx.trait_map;
let opt_applicable_traits = trait_map.find(&self.expr.id);
- for opt_applicable_traits.each |applicable_traits| {
+ for opt_applicable_traits.iter().advance |applicable_traits| {
for applicable_traits.each |trait_did| {
let coherence_info = self.fcx.ccx.coherence_info;
// Look for explicit implementations.
let opt_impl_infos =
coherence_info.extension_methods.find(trait_did);
- for opt_impl_infos.each |impl_infos| {
+ for opt_impl_infos.iter().advance |impl_infos| {
for impl_infos.each |impl_info| {
self.push_candidates_from_impl(
self.extension_candidates, *impl_info);
pub fn push_inherent_impl_candidates_for_type(&self, did: def_id) {
let opt_impl_infos =
self.fcx.ccx.coherence_info.inherent_methods.find(&did);
- for opt_impl_infos.each |impl_infos| {
+ for opt_impl_infos.iter().advance |impl_infos| {
for impl_infos.each |impl_info| {
self.push_candidates_from_impl(
self.inherent_candidates, *impl_info);
None => ()
}
- for opt_self_info.each |self_info| {
+ for opt_self_info.iter().advance |self_info| {
fcx.write_ty(self_info.self_id, self_info.self_ty);
}
for decl.inputs.iter().zip(arg_tys.iter()).advance |(input, arg)| {
};
// Add the self parameter
- for opt_self_info.each |self_info| {
+ for opt_self_info.iter().advance |self_info| {
assign(self_info.self_id, Some(self_info.self_ty));
debug!("self is assigned to %s",
fcx.infcx().ty_to_str(
variants: &mut ~[ty::VariantInfo]) {
let rty = ty::node_id_to_type(ccx.tcx, id);
for vs.each |v| {
- for v.node.disr_expr.each |e_ref| {
+ for v.node.disr_expr.iter().advance |e_ref| {
let e = *e_ref;
debug!("disr expr, checking %s",
pprust::expr_to_str(e, ccx.tcx.sess.intr()));
*/
use core::prelude::*;
+use core::iterator::IteratorUtil;
use middle::freevars::get_freevars;
use middle::ty::{re_scope};
ast::expr_match(_, ref arms) => {
tcx.region_maps.record_cleanup_scope(expr.id);
for arms.each |arm| {
- for arm.guard.each |guard| {
+ for arm.guard.iter().advance |guard| {
tcx.region_maps.record_cleanup_scope(guard.id);
}
}
}
// Check any autoderefs or autorefs that appear.
- for rcx.fcx.inh.adjustments.find(&expr.id).each |&adjustment| {
- debug!("adjustment=%?", adjustment);
- match *adjustment {
- @ty::AutoDerefRef(
- ty::AutoDerefRef {autoderefs: autoderefs, autoref: opt_autoref}) =>
- {
- let expr_ty = rcx.resolve_node_type(expr.id);
- constrain_derefs(rcx, expr, autoderefs, expr_ty);
- for opt_autoref.each |autoref| {
- guarantor::for_autoref(rcx, expr, autoderefs, autoref);
-
- // Require that the resulting region encompasses
- // the current node.
- //
- // FIXME(#6268) remove to support nested method calls
- constrain_regions_in_type_of_node(
- rcx, expr.id, ty::re_scope(expr.id), expr.span);
+ {
+ let r = rcx.fcx.inh.adjustments.find(&expr.id);
+ for r.iter().advance |&adjustment| {
+ debug!("adjustment=%?", adjustment);
+ match *adjustment {
+ @ty::AutoDerefRef(
+ ty::AutoDerefRef {autoderefs: autoderefs, autoref: opt_autoref}) =>
+ {
+ let expr_ty = rcx.resolve_node_type(expr.id);
+ constrain_derefs(rcx, expr, autoderefs, expr_ty);
+ for opt_autoref.iter().advance |autoref| {
+ guarantor::for_autoref(rcx, expr, autoderefs, autoref);
+
+ // Require that the resulting region encompasses
+ // the current node.
+ //
+ // FIXME(#6268) remove to support nested method calls
+ constrain_regions_in_type_of_node(
+ rcx, expr.id, ty::re_scope(expr.id), expr.span);
+ }
}
+ _ => {}
}
- _ => {}
}
}
}
// as loop above, but for receiver
- for receiver.each |&r| {
+ for receiver.iter().advance |&r| {
constrain_regions_in_type_of_node(
rcx, r.id, callee_region, r.span);
if implicitly_ref_args {
rcx: @mut Rcx,
expr: @ast::expr,
sub_region: ty::Region,
- sup_region: Option<ty::Region>)
- {
- for sup_region.each |r| {
+ sup_region: Option<ty::Region>) {
+ for sup_region.iter().advance |r| {
infallibly_mk_subr(rcx, true, expr.span, sub_region, *r);
}
}
debug!("guarantor::for_by_ref(expr=%?, callee_scope=%?) category=%?",
expr.id, callee_scope, expr_cat);
let minimum_lifetime = ty::re_scope(callee_scope);
- for expr_cat.guarantor.each |guarantor| {
+ for expr_cat.guarantor.iter().advance |guarantor| {
mk_subregion_due_to_derefence(rcx, expr.span,
minimum_lifetime, *guarantor);
}
ast::pat_ident(ast::bind_by_ref(_), _, opt_p) => {
link(rcx, pat.span, pat.id, guarantor);
- for opt_p.each |p| {
+ for opt_p.iter().advance |p| {
link_ref_bindings_in_pat(rcx, *p, guarantor);
}
}
ast::pat_ident(_, _, opt_p) => {
- for opt_p.each |p| {
+ for opt_p.iter().advance |p| {
link_ref_bindings_in_pat(rcx, *p, guarantor);
}
}
};
link_ref_bindings_in_pats(rcx, before, guarantor1);
- for slice.each |&p| {
+ for slice.iter().advance |&p| {
link_ref_bindings_in_pat(rcx, p, guarantor);
}
link_ref_bindings_in_pats(rcx, after, guarantor1);
{
let mut all_tys = ty::tys_in_fn_sig(fn_sig);
- for opt_self_ty.each |&self_ty| {
+ for opt_self_ty.iter().advance |&self_ty| {
all_tys.push(self_ty);
}
- for opt_self_ty.each |&t| { all_tys.push(t) }
+ for opt_self_ty.iter().advance |&t| { all_tys.push(t) }
debug!("replace_bound_regions_in_fn_sig(self_ty=%?, fn_sig=%s, \
all_tys=%?)",
*/
let mut the_stack = ~[];
- for opt_region.each |&r| { the_stack.push(r); }
+ for opt_region.iter().advance |&r| { the_stack.push(r); }
walk_ty(tcx, &mut the_stack, ty, relate_op);
fn walk_ty(tcx: ty::ctxt,
for fn_sig.inputs.each |arg| {
all_tys.push(*arg);
}
- for self_ty.each |&t| {
+ for self_ty.iter().advance |&t| {
all_tys.push(t);
}
// except according to those terms.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use middle::resolve::Impl;
use middle::ty::param_ty;
// same trait as trait_ref, we need to
// unify it with trait_ref in order to get all
// the ty vars sorted out.
- for ty::impl_trait_ref(tcx, im.did).each |&of_trait_ref|
- {
+ let r = ty::impl_trait_ref(tcx, im.did);
+ for r.iter().advance |&of_trait_ref| {
if of_trait_ref.def_id != trait_ref.def_id { loop; }
// At this point, we know that of_trait_ref is
// substitutions.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use middle::pat_util;
use middle::ty;
match fcx.inh.method_map.find(&id) {
None => {}
Some(mme) => {
- for resolve_type_vars_in_type(fcx, sp, mme.self_ty).each |t| {
- let method_map = fcx.ccx.method_map;
- let new_entry = method_map_entry { self_ty: *t, ..*mme };
- debug!("writeback::resolve_method_map_entry(id=%?, \
- new_entry=%?)",
- id, new_entry);
- method_map.insert(id, new_entry);
+ {
+ let r = resolve_type_vars_in_type(fcx, sp, mme.self_ty);
+ for r.iter().advance |t| {
+ let method_map = fcx.ccx.method_map;
+ let new_entry = method_map_entry { self_ty: *t, ..*mme };
+ debug!("writeback::resolve_method_map_entry(id=%?, \
+ new_entry=%?)",
+ id, new_entry);
+ method_map.insert(id, new_entry);
+ }
}
}
}
resolve_type_vars_for_node(wbcx, e.span, e.id);
resolve_method_map_entry(wbcx.fcx, e.span, e.id);
- for e.get_callee_id().each |callee_id| {
- resolve_method_map_entry(wbcx.fcx, e.span, *callee_id);
+ {
+ let r = e.get_callee_id();
+ for r.iter().advance |callee_id| {
+ resolve_method_map_entry(wbcx.fcx, e.span, *callee_id);
+ }
}
resolve_vtable_map_entry(wbcx.fcx, e.span, e.id);
- for e.get_callee_id().each |callee_id| {
- resolve_vtable_map_entry(wbcx.fcx, e.span, *callee_id);
+ {
+ let r = e.get_callee_id();
+ for r.iter().advance |callee_id| {
+ resolve_vtable_map_entry(wbcx.fcx, e.span, *callee_id);
+ }
}
match e.node {
let wbcx = @mut WbCtxt { fcx: fcx, success: true };
let visit = mk_visitor();
(visit.visit_block)(blk, wbcx, visit);
- for self_info.each |self_info| {
+ for self_info.iter().advance |self_info| {
resolve_type_vars_for_node(wbcx,
self_info.span,
self_info.self_id);
use core::iterator::IteratorUtil;
use core::hashmap::{HashMap, HashSet};
-use core::old_iter;
use core::result::Ok;
use core::uint;
use core::vec;
match item.node {
item_impl(_, opt_trait, _, _) => {
self.check_implementation(item,
- old_iter::to_vec(&opt_trait));
+ opt_trait.iter().transform(|&x| x).collect());
}
_ => {
// Nothing to do.
}
// Check that we have implementations of every trait method
- for trait_refs.each |trait_ref| {
+ for trait_refs.iter().advance |trait_ref| {
let trait_did =
self.trait_ref_to_trait_def_id(*trait_ref);
self.please_check_that_trait_methods_are_implemented(
// methods are provided. For each of those methods,
// if a method of that name is not inherent to the
// impl, use the provided definition in the trait.
- for trait_refs.each |trait_ref| {
+ for trait_refs.iter().advance |trait_ref| {
let trait_did =
self.trait_ref_to_trait_def_id(*trait_ref);
}
// Record all the trait methods.
- for associated_traits.each |trait_ref| {
+ for associated_traits.iter().advance |trait_ref| {
self.add_trait_method(trait_ref.def_id, *implementation);
}
*/
use core::prelude::*;
+use core::iterator::IteratorUtil;
use metadata::csearch;
use middle::ty::{substs, ty_param_bounds_and_ty};
// For both the trait and the impl, create an argument to
// represent the self argument (unless this is a static method).
// This argument will have the *transformed* self type.
- for trait_m.transformed_self_ty.each |&t| {
+ for trait_m.transformed_self_ty.iter().advance |&t| {
trait_fn_args.push(t);
}
- for impl_m.transformed_self_ty.each |&t| {
+ for impl_m.transformed_self_ty.iter().advance |&t| {
impl_fn_args.push(t);
}
let cms = convert_methods(ccx, *ms, selfty,
&i_ty_generics, generics,
parent_visibility);
- for opt_trait_ref.each |t| {
+ for opt_trait_ref.iter().advance |t| {
check_methods_against_trait(ccx, generics, rp, selfty, *t, cms);
}
}
use core::result;
use core::vec;
+use core::iterator::IteratorUtil;
use extra::list::Nil;
use extra::smallintmap::SmallIntMap;
use syntax::ast::{m_imm, m_mutbl};
fmt!("%s%s", mk_msg(Some(self.ty_to_str(e)), actual_ty), error_str));
}
}
- for err.each |err| {
+ for err.iter().advance |err| {
ty::note_and_explain_type_err(self.tcx, *err)
}
}
use syntax::print::pprust;
use syntax::{ast, ast_util};
+use core::iterator::IteratorUtil;
use core::str;
use core::vec;
let base = ast_map::path_to_str(path, tcx.sess.intr());
if tcx.sess.verbose() && self.substs.self_ty.is_some() {
let mut all_tps = copy self.substs.tps;
- for self.substs.self_ty.each |&t| { all_tps.push(t); }
+ for self.substs.self_ty.iter().advance |&t| { all_tps.push(t); }
parameterized(tcx, base, self.substs.self_r, all_tps)
} else {
parameterized(tcx, base, self.substs.self_r,
return true;
}
else {
- for self_id.each |pth| {
+ for self_id.iter().advance |pth| {
if pth.starts_with("rust_") // because p is already normalized
&& match p.filestem() {
Some(s) => str::eq_slice(s, pth.slice(5, pth.len())),
target_exec.to_str(), target_lib,
maybe_executable, maybe_library);
- for maybe_executable.each |exec| {
+ for maybe_executable.iter().advance |exec| {
debug!("Copying: %s -> %s", exec.to_str(), target_exec.to_str());
if !(os::mkdir_recursive(&target_exec.dir_path(), u_rwx) &&
os::copy_file(exec, &target_exec)) {
cond.raise((copy *exec, copy target_exec));
}
}
- for maybe_library.each |lib| {
+ for maybe_library.iter().advance |lib| {
let target_lib = (copy target_lib).expect(fmt!("I built %s but apparently \
didn't install it!", lib.to_str()));
debug!("Copying: %s -> %s", lib.to_str(), target_lib.to_str());
use hash::Hash;
use old_iter::BaseIter;
use old_iter;
+use iterator::{Iterator, IteratorUtil};
use option::{None, Option, Some};
use rand::RngUtil;
use rand;
/// Visit all key-value pairs
fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool {
for self.buckets.each |bucket| {
- for bucket.each |pair| {
+ for bucket.iter().advance |pair| {
if !blk(&pair.key, &pair.value) {
return false;
}
///
/// let a = [0];
/// let b = [1];
- /// let mut it = a.iter().chain(b.iter());
+ /// let mut it = a.iter().chain_(b.iter());
/// assert_eq!(it.next().get(), &0);
/// assert_eq!(it.next().get(), &1);
/// assert!(it.next().is_none());
/// ~~~
- fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<A, Self, U>;
+ fn chain_<U: Iterator<A>>(self, other: U) -> ChainIterator<A, Self, U>;
/// Creates an iterator which iterates over both this and the specified
/// iterators simultaneously, yielding the two elements as pairs. When
/// ~~~
fn skip(self, n: uint) -> SkipIterator<A, Self>;
+ // FIXME: #5898: should be called take
/// Creates an iterator which yields the first `n` elements of this
/// iterator, and then it will always return None.
///
/// use std::iterator::*;
///
/// let a = [1, 2, 3, 4, 5];
- /// let mut it = a.iter().take(3);
+ /// let mut it = a.iter().take_(3);
/// assert_eq!(it.next().get(), &1);
/// assert_eq!(it.next().get(), &2);
/// assert_eq!(it.next().get(), &3);
/// assert!(it.next().is_none());
/// ~~~
- fn take(self, n: uint) -> TakeIterator<A, Self>;
+ fn take_(self, n: uint) -> TakeIterator<A, Self>;
/// Creates a new iterator which behaves in a similar fashion to foldl.
/// There is a state which is passed between each iteration and can be
///
/// let a = [1, 2, 3, 4, 5];
/// let mut it = a.iter();
- /// assert!(it.any(|&x| *x == 3));
- /// assert!(!it.any(|&x| *x == 3));
+ /// assert!(it.any_(|&x| *x == 3));
+ /// assert!(!it.any_(|&x| *x == 3));
/// ~~~
- fn any(&mut self, f: &fn(A) -> bool) -> bool;
+ fn any_(&mut self, f: &fn(A) -> bool) -> bool;
}
/// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also
/// In the future these will be default methods instead of a utility trait.
impl<A, T: Iterator<A>> IteratorUtil<A> for T {
#[inline(always)]
- fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<A, T, U> {
+ fn chain_<U: Iterator<A>>(self, other: U) -> ChainIterator<A, T, U> {
ChainIterator{a: self, b: other, flag: false}
}
SkipIterator{iter: self, n: n}
}
+ // FIXME: #5898: should be called take
#[inline(always)]
- fn take(self, n: uint) -> TakeIterator<A, T> {
+ fn take_(self, n: uint) -> TakeIterator<A, T> {
TakeIterator{iter: self, n: n}
}
}
#[inline(always)]
- fn any(&mut self, f: &fn(A) -> bool) -> bool {
+ fn any_(&mut self, f: &fn(A) -> bool) -> bool {
for self.advance |x| { if f(x) { return true; } }
return false;
}
#[test]
fn test_counter_from_iter() {
- let mut it = Counter::new(0, 5).take(10);
+ let mut it = Counter::new(0, 5).take_(10);
let xs: ~[int] = iter::FromIter::from_iter::<int, ~[int]>(|f| it.advance(f));
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
}
let xs = [0u, 1, 2, 3, 4, 5];
let ys = [30u, 40, 50, 60];
let expected = [0, 1, 2, 3, 4, 5, 30, 40, 50, 60];
- let mut it = xs.iter().chain(ys.iter());
+ let mut it = xs.iter().chain_(ys.iter());
let mut i = 0;
for it.advance |&x| {
assert_eq!(x, expected[i]);
}
assert_eq!(i, expected.len());
- let ys = Counter::new(30u, 10).take(4);
- let mut it = xs.iter().transform(|&x| x).chain(ys);
+ let ys = Counter::new(30u, 10).take_(4);
+ let mut it = xs.iter().transform(|&x| x).chain_(ys);
let mut i = 0;
for it.advance |x| {
assert_eq!(x, expected[i]);
#[test]
fn test_filter_map() {
- let mut it = Counter::new(0u, 1u).take(10)
+ let mut it = Counter::new(0u, 1u).take_(10)
.filter_map(|x| if x.is_even() { Some(x*x) } else { None });
assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
}
fn test_iterator_take() {
let xs = [0u, 1, 2, 3, 5, 13, 15, 16, 17, 19];
let ys = [0u, 1, 2, 3, 5];
- let mut it = xs.iter().take(5);
+ let mut it = xs.iter().take_(5);
let mut i = 0;
for it.advance |&x| {
assert_eq!(x, ys[i]);
#[test]
fn test_any() {
let v = ~&[1, 2, 3, 4, 5];
- assert!(v.iter().any(|&x| x < 10));
- assert!(v.iter().any(|&x| x.is_even()));
- assert!(!v.iter().any(|&x| x > 100));
- assert!(!v.slice(0, 0).iter().any(|_| fail!()));
+ assert!(v.iter().any_(|&x| x < 10));
+ assert!(v.iter().any_(|&x| x.is_even()));
+ assert!(!v.iter().any_(|&x| x > 100));
+ assert!(!v.slice(0, 0).iter().any_(|_| fail!()));
}
}
use kinds::Copy;
use util;
use num::Zero;
-use old_iter::{BaseIter, MutableIter, ExtendedIter};
-use old_iter;
use iterator::Iterator;
use str::StrSlice;
use clone::DeepClone;
#[cfg(test)] use str;
+#[cfg(test)] use iterator::IteratorUtil;
/// The option type
#[deriving(Clone, DeepClone, Eq)]
}
}
-impl<T> BaseIter<T> for Option<T> {
- /// Performs an operation on the contained value by reference
- #[inline(always)]
- fn each<'a>(&'a self, f: &fn(x: &'a T) -> bool) -> bool {
- match *self { None => true, Some(ref t) => { f(t) } }
- }
-
- #[inline(always)]
- fn size_hint(&self) -> Option<uint> {
- if self.is_some() { Some(1) } else { Some(0) }
- }
-}
-
-impl<T> MutableIter<T> for Option<T> {
- #[inline(always)]
- fn each_mut<'a>(&'a mut self, f: &fn(&'a mut T) -> bool) -> bool {
- match *self { None => true, Some(ref mut t) => { f(t) } }
- }
-}
-
-impl<A> ExtendedIter<A> for Option<A> {
- pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) -> bool {
- old_iter::eachi(self, blk)
- }
- pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
- old_iter::all(self, blk)
- }
- pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
- old_iter::any(self, blk)
- }
- pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
- old_iter::foldl(self, b0, blk)
- }
- pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
- old_iter::position(self, f)
- }
- fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
- old_iter::map_to_vec(self, op)
- }
- fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
- -> ~[B] {
- old_iter::flat_map_to_vec(self, op)
- }
-}
-
impl<T> Option<T> {
+ /// Return an iterator over the possibly contained value
#[inline]
pub fn iter<'r>(&'r self) -> OptionIterator<'r, T> {
match *self {
}
}
+ /// Return a mutable iterator over the possibly contained value
#[inline]
pub fn mut_iter<'r>(&'r mut self) -> OptionMutIterator<'r, T> {
match *self {
}
}
+/// Immutable iterator over an `Option<A>`
pub struct OptionIterator<'self, A> {
priv opt: Option<&'self A>
}
}
}
+/// Mutable iterator over an `Option<A>`
pub struct OptionMutIterator<'self, A> {
priv opt: Option<&'self mut A>
}
let x = Some(());
let mut y = Some(5);
let mut y2 = 0;
- for x.each |_x| {
+ for x.iter().advance |_x| {
y2 = y.swap_unwrap();
}
assert_eq!(y2, 5);
setenv("HOME", "");
assert!(os::homedir().is_none());
- for oldhome.each |s| { setenv("HOME", *s) }
+ for oldhome.iter().advance |s| { setenv("HOME", *s) }
}
#[test]
in_fd, out_fd, err_fd);
unsafe {
- for in_pipe.each |pipe| { libc::close(pipe.in); }
- for out_pipe.each |pipe| { libc::close(pipe.out); }
- for err_pipe.each |pipe| { libc::close(pipe.out); }
+ for in_pipe.iter().advance |pipe| { libc::close(pipe.in); }
+ for out_pipe.iter().advance |pipe| { libc::close(pipe.out); }
+ for err_pipe.iter().advance |pipe| { libc::close(pipe.out); }
}
Process {
* If the child has already been finished then the exit code is returned.
*/
pub fn finish(&mut self) -> int {
- for self.exit_code.each |&code| {
+ for self.exit_code.iter().advance |&code| {
return code;
}
self.close_input();
use util;
use unstable::sync::{Exclusive, exclusive};
use rt::local::Local;
+use iterator::{Iterator, IteratorUtil};
#[cfg(test)] use task::default_task_opts;
#[cfg(test)] use comm;
* Step 3: Maybe unwind; compute return info for our caller.
*##########################################################*/
if need_unwind && !nobe_is_dead {
- for bail_opt.each |bail_blk| {
+ for bail_opt.iter().advance |bail_blk| {
do with_parent_tg(&mut nobe.parent_group) |tg_opt| {
(*bail_blk)(tg_opt)
}
// If we are failing, the whole taskgroup needs to die.
if rt::rust_task_is_unwinding(self.me) {
- for this.notifier.each_mut |x| {
+ for this.notifier.mut_iter().advance |x| {
x.failed = true;
}
// Take everybody down with us.
ancestors: AncestorList,
is_main: bool,
mut notifier: Option<AutoNotify>) -> TCB {
- for notifier.each_mut |x| {
+ for notifier.mut_iter().advance |x| {
x.failed = false;
}
*/
-use cmp::Eq;
use prelude::*;
+use iterator::IteratorUtil;
/*
* We have a 'ct' (compile-time) module that parses format strings into a
let headsize = match head { Some(_) => 1, _ => 0 };
let uwidth : uint = match cv.width {
CountImplied => {
- for head.each |&c| {
+ for head.iter().advance |&c| {
buf.push_char(c);
}
return buf.push_str(s);
};
let strlen = str::char_len(s) + headsize;
if uwidth <= strlen {
- for head.each |&c| {
+ for head.iter().advance |&c| {
buf.push_char(c);
}
return buf.push_str(s);
let mut padchar = ' ';
let diff = uwidth - strlen;
if have_flag(cv.flags, flag_left_justify) {
- for head.each |&c| {
+ for head.iter().advance |&c| {
buf.push_char(c);
}
buf.push_str(s);
// instead.
if signed && zero_padding {
- for head.each |&head| {
+ for head.iter().advance |&head| {
if head == '+' || head == '-' || head == ' ' {
buf.push_char(head);
buf.push_str(padstr);
}
}
buf.push_str(padstr);
- for head.each |&c| {
+ for head.iter().advance |&c| {
buf.push_char(c);
}
buf.push_str(s);
use visit;
use syntax::parse::token::special_idents;
+use core::iterator::IteratorUtil;
use core::cmp;
use core::hashmap::HashMap;
use core::vec;
pub fn map_expr(ex: @expr, cx: @mut Ctx, v: visit::vt<@mut Ctx>) {
cx.map.insert(ex.id, node_expr(ex));
// Expressions which are or might be calls:
- for ex.get_callee_id().each |callee_id| {
- cx.map.insert(*callee_id, node_callee_scope(ex));
+ {
+ let r = ex.get_callee_id();
+ for r.iter().advance |callee_id| {
+ cx.map.insert(*callee_id, node_callee_scope(ex));
+ }
}
visit::visit_expr(ex, cx, v);
}
use core::int;
use core::option;
use core::to_bytes;
+use core::iterator::IteratorUtil;
pub fn path_name_i(idents: &[ident]) -> ~str {
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
},
visit_expr: |e, t, vt| {
- for e.get_callee_id().each |callee_id| {
- vfn(*callee_id, t);
+ {
+ let r = e.get_callee_id();
+ for r.iter().advance |callee_id| {
+ vfn(*callee_id, t);
+ }
}
vfn(e.id, t);
visit::visit_expr(e, t, vt);
}
pat_vec(ref before, ref slice, ref after) => {
before.each(|&p| walk_pat(p, it)) &&
- slice.each(|&p| walk_pat(p, it)) &&
- after.each(|&p| walk_pat(p, it))
+ slice.iter().advance(|&p| walk_pat(p, it)) &&
+ after.iter().advance(|&p| walk_pat(p, it))
}
pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _, _) |
pat_enum(_, _) => {
// except according to those terms.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use codemap::{Pos, span};
use codemap;
}
fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) {
- for sp.expn_info.each |ei| {
+ for sp.expn_info.iter().advance |ei| {
let ss = ei.callee.span.map_default(@~"", |span| @cm.span_to_str(*span));
print_diagnostic(*ss, note,
fmt!("in expansion of %s!", ei.callee.name));
_ => ()
}
// visit optional subpattern of pat_ident:
- for inner.each |subpat: &@ast::pat| { (v.visit_pat)(*subpat, ident_accum, v) }
+ for inner.iter().advance |subpat: &@ast::pat| {
+ (v.visit_pat)(*subpat, ident_accum, v)
+ }
}
// use the default traversal for non-pat_idents
_ => visit::visit_pat(p,ident_accum,v)
use core::str;
use core::u64;
use core::uint;
+use core::iterator::IteratorUtil;
// The @ps is stored here to prevent recursive type.
pub enum ann_node<'self> {
}
pub fn print_opt_lifetime(s: @ps, lifetime: Option<@ast::Lifetime>) {
- for lifetime.each |l| {
+ for lifetime.iter().advance |l| {
print_lifetime(s, *l);
nbsp(s);
}
print_block(s, blk);
}
ast::expr_loop(ref blk, opt_ident) => {
- for opt_ident.each |ident| {
+ for opt_ident.iter().advance |ident| {
word(s.s, "'");
print_ident(s, *ident);
word_space(s, ":");
ast::expr_break(opt_ident) => {
word(s.s, "break");
space(s.s);
- for opt_ident.each |ident| {
+ for opt_ident.iter().advance |ident| {
word(s.s, "'");
print_ident(s, *ident);
space(s.s);
ast::expr_again(opt_ident) => {
word(s.s, "loop");
space(s.s);
- for opt_ident.each |ident| {
+ for opt_ident.iter().advance |ident| {
word(s.s, "'");
print_ident(s, *ident);
space(s.s)
if path.rp.is_some() || !path.types.is_empty() {
word(s.s, "<");
- for path.rp.each |r| {
+ for path.rp.iter().advance |r| {
print_lifetime(s, *r);
if !path.types.is_empty() {
word_space(s, ",");
do commasep(s, inconsistent, *before) |s, p| {
print_pat(s, p, refutable);
}
- for slice.each |&p| {
+ for slice.iter().advance |&p| {
if !before.is_empty() { word_space(s, ","); }
word(s.s, "..");
print_pat(s, p, refutable);
// self type and the args all in the same box.
box(s, 0u, inconsistent);
let mut first = true;
- for opt_explicit_self.each |explicit_self| {
+ for opt_explicit_self.iter().advance |explicit_self| {
first = !print_explicit_self(s, *explicit_self);
}
// self type and the args all in the same box.
box(s, 0u, inconsistent);
let mut first = true;
- for opt_explicit_self.each |explicit_self| {
+ for opt_explicit_self.iter().advance |explicit_self| {
first = !print_explicit_self(s, *explicit_self);
}
for decl.inputs.each |arg| {
// except according to those terms.
use core::prelude::*;
+use core::iterator::IteratorUtil;
use abi::AbiSet;
use ast::*;
}
item_impl(ref tps, ref traits, ty, ref methods) => {
(v.visit_generics)(tps, e, v);
- for traits.each |&p| {
+ for traits.iter().advance |&p| {
visit_trait_ref(p, e, v);
}
(v.visit_ty)(ty, e, v);
}
}
// Visit the disr expr if it exists
- for vr.node.disr_expr.each |ex| { (v.visit_expr)(*ex, e, v) }
+ for vr.node.disr_expr.iter().advance |ex| { (v.visit_expr)(*ex, e, v) }
}
}
match p.node {
pat_enum(path, ref children) => {
visit_path(path, e, v);
- for children.each |children| {
- for children.each |child| { (v.visit_pat)(*child, e, v); }
+ for children.iter().advance |children| {
+ for children.iter().advance |child| { (v.visit_pat)(*child, e, v); }
}
}
pat_struct(path, ref fields, _) => {
},
pat_ident(_, path, ref inner) => {
visit_path(path, e, v);
- for inner.each |subpat| { (v.visit_pat)(*subpat, e, v) }
+ for inner.iter().advance |subpat| { (v.visit_pat)(*subpat, e, v) }
}
pat_lit(ex) => (v.visit_expr)(ex, e, v),
pat_range(e1, e2) => {
for before.each |elt| {
(v.visit_pat)(*elt, e, v);
}
- for slice.each |elt| {
+ for slice.iter().advance |elt| {
(v.visit_pat)(*elt, e, v);
}
for after.each |tail| {
}
pub fn visit_arm<E: Copy>(a: &arm, e: E, v: vt<E>) {
- for a.pats.each |p| { (v.visit_pat)(*p, e, v); }
+ for a.pats.iter().advance |p| { (v.visit_pat)(*p, e, v); }
visit_expr_opt(a.guard, e, v);
(v.visit_block)(&a.body, e, v);
}
while keys.len() < n {
let k = r.gen_uint_range(0u, graph.len());
- if graph[k].len() > 0u && graph[k].iter().any(|i| {
+ if graph[k].len() > 0u && graph[k].iter().any_(|i| {
*i != k as node_id
}) {
keys.insert(k as node_id);
}
let mut i = 0;
- while colors.iter().any(is_gray) {
+ while colors.iter().any_(is_gray) {
// Do the BFS.
info!("PBFS iteration %?", i);
i += 1;
}
// Usable at all:
- let mut any_negative = do v.iter().any |e| { e.is_negative() };
+ let mut any_negative = do v.iter().any_ |e| { e.is_negative() };
assert!(any_negative);
// Higher precedence than assignments:
- any_negative = do v.iter().any |e| { e.is_negative() };
+ any_negative = do v.iter().any_ |e| { e.is_negative() };
assert!(any_negative);
// Higher precedence than unary operations:
let abs_v = do vec::map(v) |e| { e.abs() };
assert!(do abs_v.iter().all |e| { e.is_positive() });
- assert!(!do abs_v.iter().any |e| { e.is_negative() });
+ assert!(!do abs_v.iter().any_ |e| { e.is_negative() });
// Usable in funny statement-like forms:
- if !do v.iter().any |e| { e.is_positive() } {
+ if !do v.iter().any_ |e| { e.is_positive() } {
assert!(false);
}
match do v.iter().all |e| { e.is_negative() } {
false => { }
}
match 3 {
- _ if do v.iter().any |e| { e.is_negative() } => {
+ _ if do v.iter().any_ |e| { e.is_negative() } => {
}
_ => {
fail!("wrong answer.");
// In the tail of a block
let w =
- if true { do abs_v.iter().any |e| { e.is_positive() } }
+ if true { do abs_v.iter().any_ |e| { e.is_positive() } }
else { false };
assert!(w);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::old_iter;
-
trait thing<A> {
fn foo(&self) -> Option<A>;
}
struct A { a: int }
pub fn main() {
-
- for old_iter::eachi(&(Some(A {a: 0}))) |i, a| {
- debug!("%u %d", i, a.a);
- }
-
let _x: Option<float> = foo_func(0);
}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-fn is_even(x: &uint) -> bool { (*x % 2) == 0 }
-
-pub fn main() {
- assert!(![1u, 2u].all(is_even));
- assert!([2u, 4u].all(is_even));
- assert!([].all(is_even));
-
- assert!(!old_iter::all(&Some(1u), is_even));
- assert!(old_iter::all(&Some(2u), is_even));
- assert!(old_iter::all(&None::<uint>, is_even));
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-fn is_even(x: &uint) -> bool { (*x % 2) == 0 }
-
-pub fn main() {
- assert!(![1u, 3u].any(is_even));
- assert!([1u, 2u].any(is_even));
- assert!(![].any(is_even));
-
- assert!(!old_iter::any(&Some(1u), is_even));
- assert!(old_iter::any(&Some(2u), is_even));
- assert!(!old_iter::any(&None::<uint>, is_even));
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-pub fn main() {
- assert_eq!([].contains(&22u), false);
- assert_eq!([1u, 3u].contains(&22u), false);
- assert_eq!([22u, 1u, 3u].contains(&22u), true);
- assert_eq!([1u, 22u, 3u].contains(&22u), true);
- assert_eq!([1u, 3u, 22u].contains(&22u), true);
- assert_eq!(old_iter::contains(&None::<uint>, &22u), false);
- assert_eq!(old_iter::contains(&Some(1u), &22u), false);
- assert_eq!(old_iter::contains(&Some(22u), &22u), true);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-pub fn main() {
- assert_eq!([].count(&22u), 0u);
- assert_eq!([1u, 3u].count(&22u), 0u);
- assert_eq!([22u, 1u, 3u].count(&22u), 1u);
- assert_eq!([22u, 1u, 22u].count(&22u), 2u);
- assert_eq!(old_iter::count(&None::<uint>, &22u), 0u);
- assert_eq!(old_iter::count(&Some(1u), &22u), 0u);
- assert_eq!(old_iter::count(&Some(22u), &22u), 1u);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-pub fn main() {
- let mut c = 0u;
- for [1u, 2u, 3u, 4u, 5u].eachi |i, v| {
- assert_eq!((i + 1u), *v);
- c += 1u;
- }
- assert_eq!(c, 5u);
-
- for old_iter::eachi(&None::<uint>) |i, v| { fail!(); }
-
- let mut c = 0u;
- for old_iter::eachi(&Some(1u)) |i, v| {
- assert_eq!((i + 1u), *v);
- c += 1u;
- }
- assert_eq!(c, 1u);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-fn is_even(x: &uint) -> bool { (*x % 2) == 0 }
-
-pub fn main() {
- assert_eq!([1, 3].filter_to_vec(is_even), ~[]);
- assert_eq!([1, 2, 3].filter_to_vec(is_even), ~[2]);
- assert_eq!(old_iter::filter_to_vec(&None::<uint>, is_even), ~[]);
- assert_eq!(old_iter::filter_to_vec(&Some(1u), is_even), ~[]);
- assert_eq!(old_iter::filter_to_vec(&Some(2u), is_even), ~[2]);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-fn repeat(x: &uint) -> ~[uint] { ~[*x, *x] }
-
-fn incd_if_even(x: &uint) -> Option<uint> {
- if (*x % 2u) == 0u {Some(*x + 1u)} else {None}
-}
-
-pub fn main() {
- assert_eq!((~[1u, 3u]).flat_map_to_vec(repeat), ~[1u, 1u, 3u, 3u]);
- assert_eq!((~[]).flat_map_to_vec(repeat), ~[]);
- assert_eq!(old_iter::flat_map_to_vec(&None::<uint>, repeat), ~[]);
- assert_eq!(old_iter::flat_map_to_vec(&Some(1u), repeat), ~[1u, 1u]);
- assert_eq!(old_iter::flat_map_to_vec(&Some(2u), repeat), ~[2u, 2u]);
-
- assert_eq!((~[1u, 2u, 5u]).flat_map_to_vec(incd_if_even), ~[3u]);
- assert_eq!((~[]).flat_map_to_vec(incd_if_even), ~[]);
- assert_eq!(old_iter::flat_map_to_vec(&None::<uint>, incd_if_even), ~[]);
- assert_eq!(old_iter::flat_map_to_vec(&Some(1u), incd_if_even), ~[]);
- assert_eq!(old_iter::flat_map_to_vec(&Some(2u), incd_if_even), ~[3u]);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-fn add(x: &float, y: &uint) -> float { *x + ((*y) as float) }
-
-pub fn main() {
- assert_eq!([1u, 3u].foldl(20f, add), 24f);
- assert_eq!([].foldl(20f, add), 20f);
- assert_eq!(old_iter::foldl(&None::<uint>, 20f, add), 20f);
- assert_eq!(old_iter::foldl(&Some(1u), 20f, add), 21f);
- assert_eq!(old_iter::foldl(&Some(2u), 20f, add), 22f);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-fn inc(x: &uint) -> uint { *x + 1 }
-
-pub fn main() {
- assert_eq!([1, 3].map_to_vec(inc), ~[2, 4]);
- assert_eq!([1, 2, 3].map_to_vec(inc), ~[2, 3, 4]);
- assert_eq!(old_iter::map_to_vec(&None::<uint>, inc), ~[]);
- assert_eq!(old_iter::map_to_vec(&Some(1u), inc), ~[2]);
- assert_eq!(old_iter::map_to_vec(&Some(2u), inc), ~[3]);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-fn is_even(x: uint) -> bool { (x % 2u) == 0u }
-
-pub fn main() {
- assert_eq!([1u, 3u].min(), 1u);
- assert_eq!([3u, 1u].min(), 1u);
- assert_eq!(old_iter::min(&Some(1u)), 1u);
-
- assert_eq!([1u, 3u].max(), 3u);
- assert_eq!([3u, 1u].max(), 3u);
- assert_eq!(old_iter::max(&Some(3u)), 3u);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::old_iter;
-
-pub fn main() {
- assert_eq!([1u, 3u].to_vec(), ~[1u, 3u]);
- let e: ~[uint] = ~[];
- assert_eq!(e.to_vec(), ~[]);
- assert_eq!(old_iter::to_vec(&None::<uint>), ~[]);
- assert_eq!(old_iter::to_vec(&Some(1u)), ~[1u]);
- assert_eq!(old_iter::to_vec(&Some(2u)), ~[2u]);
-}
let tests = __test::tests;
assert!(
- tests.iter().any(|t| t.desc.name.to_str() == ~"shouldignore" && t.desc.ignore));
+ tests.iter().any_(|t| t.desc.name.to_str() == ~"shouldignore" && t.desc.ignore));
assert!(
- tests.iter().any(|t| t.desc.name.to_str() == ~"shouldnotignore" && !t.desc.ignore));
+ tests.iter().any_(|t| t.desc.name.to_str() == ~"shouldnotignore" && !t.desc.ignore));
}