auto merge of #6999 : thestinger/rust/each-fn-kill, r=thestinger

This commit is contained in:
bors 2013-06-07 11:55:36 -07:00
commit b8cf2f8056
22 changed files with 82 additions and 188 deletions

View File

@ -24,6 +24,7 @@
use core::prelude::*;
use core::iterator::IteratorUtil;
use core::str;
use core::uint;
use core::vec;
@ -173,7 +174,7 @@ pub fn sha1() -> @Sha1 {
fn mk_result(st: &mut Sha1State) -> ~[u8] {
if !(*st).computed { pad_msg(st); (*st).computed = true; }
let mut rs: ~[u8] = ~[];
for vec::each_mut((*st).h) |ptr_hpart| {
for st.h.mut_iter().advance |ptr_hpart| {
let hpart = *ptr_hpart;
let a = (hpart >> 24u32 & 0xFFu32) as u8;
let b = (hpart >> 16u32 & 0xFFu32) as u8;

View File

@ -18,6 +18,7 @@
use core::prelude::*;
use core::iterator::IteratorUtil;
use core::cast;
use core::io;
use core::str;
@ -895,7 +896,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
fn reset(&mut self, bits: &mut [uint]) {
let e = if self.dfcx.oper.initial_value() {uint::max_value} else {0};
for vec::each_mut(bits) |b| { *b = e; }
for bits.mut_iter().advance |b| { *b = e; }
}
fn add_to_entry_set(&mut self, id: ast::node_id, pred_bits: &[uint]) {

View File

@ -17,6 +17,7 @@ use middle::typeck;
use util::ppaux::{Repr, ty_to_str};
use util::ppaux::UserString;
use core::iterator::IteratorUtil;
use core::vec;
use syntax::ast::*;
use syntax::attr::attrs_contains_name;
@ -268,7 +269,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
ts.repr(cx.tcx),
type_param_defs.repr(cx.tcx));
}
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
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)
}
}
@ -309,7 +310,7 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
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 vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
check_bounds(cx, aty.id, aty.span, ty, type_param_def)
}
}

View File

@ -19,6 +19,7 @@ use middle::trans::common::*;
use middle::ty;
use util::ppaux::ty_to_str;
use core::iterator::IteratorUtil;
use core::vec;
use syntax::ast;
use syntax::ast_map::path_name;
@ -75,7 +76,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id,
ast::item_enum(_, _) => {
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
for vec::each2(*vs_here, *vs_there) |here, there| {
for vs_here.iter().zip(vs_there.iter()).advance |(here, there)| {
if there.id == fn_id { my_id = here.id.node; }
ccx.external.insert(there.id, Some(here.id.node));
}

View File

@ -33,6 +33,7 @@ use middle::trans::inline;
use middle::ty;
use middle::typeck;
use core::iterator::IteratorUtil;
use core::option::{Some, None};
use core::uint;
use core::vec;
@ -264,7 +265,7 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
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 vec::each2(*type_uses, *ts) |uses, subst| {
for type_uses.iter().zip(ts.iter()).advance |(uses, subst)| {
type_needs(cx, *uses, *subst)
}
}
@ -302,7 +303,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
for opt_ts.each |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 vec::each2(*uses_for_ts, *ts) |uses, subst| {
for uses_for_ts.iter().zip(ts.iter()).advance |(uses, subst)| {
type_needs(cx, *uses, *subst)
}
}

View File

@ -18,8 +18,8 @@ use middle::typeck::check::{instantiate_path, lookup_def};
use middle::typeck::check::{structure_of, valid_range_bounds};
use middle::typeck::require_same_types;
use core::iterator::IteratorUtil;
use core::hashmap::{HashMap, HashSet};
use core::vec;
use syntax::ast;
use syntax::ast_util;
use syntax::codemap::span;
@ -232,7 +232,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
if !error_happened {
for subpats.each |pats| {
for vec::each2(*pats, arg_types) |subpat, arg_ty| {
for pats.iter().zip(arg_types.iter()).advance |(subpat, arg_ty)| {
check_pat(pcx, *subpat, *arg_ty);
}
}

View File

@ -110,6 +110,8 @@ use util::common::{block_query, indenter, loop_query};
use util::ppaux::{bound_region_to_str};
use util::ppaux;
use core::iterator::IteratorUtil;
use core::cast::transmute;
use core::hashmap::HashMap;
use core::result;
@ -412,7 +414,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
for opt_self_info.each |self_info| {
fcx.write_ty(self_info.self_id, self_info.self_ty);
}
for vec::each2(decl.inputs, arg_tys) |input, arg| {
for decl.inputs.iter().zip(arg_tys.iter()).advance |(input, arg)| {
fcx.write_ty(input.id, *arg);
}
@ -449,7 +451,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
}
// Add formal parameters.
for vec::each2(arg_tys, decl.inputs) |arg_ty, input| {
for arg_tys.iter().zip(decl.inputs.iter()).advance |(arg_ty, input)| {
// Create type variables for each argument.
do pat_util::pat_bindings(tcx.def_map, input.pat)
|_bm, pat_id, _sp, _path| {

View File

@ -54,6 +54,7 @@ use syntax::visit::{Visitor, SimpleVisitor};
use syntax::visit::{visit_mod};
use util::ppaux::ty_to_str;
use core::iterator::IteratorUtil;
use core::hashmap::{HashMap, HashSet};
use core::old_iter;
use core::result::Ok;
@ -617,9 +618,9 @@ impl CoherenceChecker {
// Check to ensure that each parameter binding respected its
// kind bounds.
for [ a, b ].each |result| {
for vec::each2(result.type_variables,
*result.type_param_defs)
|ty_var, type_param_def|
for result.type_variables.iter()
.zip(result.type_param_defs.iter())
.advance |(ty_var, type_param_def)|
{
if type_param_def.bounds.builtin_bounds.contains_elem(
ty::BoundCopy)

View File

@ -55,7 +55,7 @@ pub trait IteratorUtil<A> {
/// assert_eq!(it.next().get(), &1);
/// assert!(it.next().is_none());
/// ~~~
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<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
@ -73,7 +73,7 @@ pub trait IteratorUtil<A> {
/// assert_eq!(it.next().get(), (&0, &1));
/// assert!(it.next().is_none());
/// ~~~
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<Self, U>;
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<A, Self, B, U>;
// FIXME: #5898: should be called map
/// Creates a new iterator which will apply the specified function to each
@ -139,7 +139,7 @@ pub trait IteratorUtil<A> {
/// assert_eq!(it.next().get(), (1, &200));
/// assert!(it.next().is_none());
/// ~~~
fn enumerate(self) -> EnumerateIterator<Self>;
fn enumerate(self) -> EnumerateIterator<A, Self>;
/// Creates an iterator which invokes the predicate on elements until it
/// returns true. Once the predicate returns true, all further elements are
@ -285,7 +285,8 @@ pub trait IteratorUtil<A> {
/// let a = [1, 2, 3, 4, 5];
/// assert!(a.iter().last().get() == &5);
/// ~~~
fn last(&mut self) -> Option<A>;
// FIXME: #5898: should be called `last`
fn last_(&mut self) -> Option<A>;
/// Performs a fold operation over the entire iterator, returning the
/// eventual state at the end of the iteration.
@ -349,12 +350,12 @@ pub trait IteratorUtil<A> {
/// 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<T, U> {
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<A, T, U> {
ChainIterator{a: self, b: other, flag: false}
}
#[inline(always)]
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<A, T, B, U> {
ZipIterator{a: self, b: other}
}
@ -375,7 +376,7 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
}
#[inline(always)]
fn enumerate(self) -> EnumerateIterator<T> {
fn enumerate(self) -> EnumerateIterator<A, T> {
EnumerateIterator{iter: self, count: 0}
}
@ -437,7 +438,7 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
/// Return the last item yielded by an iterator.
#[inline(always)]
fn last(&mut self) -> Option<A> {
fn last_(&mut self) -> Option<A> {
let mut last = None;
for self.advance |x| { last = Some(x); }
last
@ -570,13 +571,14 @@ impl<A: Ord, T: Iterator<A>> OrdIterator<A> for T {
}
/// An iterator which strings two iterators together
pub struct ChainIterator<T, U> {
// FIXME #6967: Dummy A parameter to get around type inference bug
pub struct ChainIterator<A, T, U> {
priv a: T,
priv b: U,
priv flag: bool
}
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<A, T, U> {
#[inline]
fn next(&mut self) -> Option<A> {
if self.flag {
@ -593,12 +595,13 @@ impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
}
/// An iterator which iterates two other iterators simultaneously
pub struct ZipIterator<T, U> {
// FIXME #6967: Dummy A & B parameters to get around type inference bug
pub struct ZipIterator<A, T, B, U> {
priv a: T,
priv b: U
}
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<T, U> {
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<A, T, B, U> {
#[inline]
fn next(&mut self) -> Option<(A, B)> {
match (self.a.next(), self.b.next()) {
@ -664,12 +667,13 @@ impl<'self, A, B, T: Iterator<A>> Iterator<B> for FilterMapIterator<'self, A, B,
}
/// An iterator which yields the current count and the element during iteration
pub struct EnumerateIterator<T> {
// FIXME #6967: Dummy A parameter to get around type inference bug
pub struct EnumerateIterator<A, T> {
priv iter: T,
priv count: uint
}
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<T> {
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<A, T> {
#[inline]
fn next(&mut self) -> Option<(uint, A)> {
match self.iter.next() {
@ -887,7 +891,7 @@ mod tests {
let expected = [0, 1, 2, 3, 4, 5, 30, 40, 50, 60];
let mut it = xs.iter().chain(ys.iter());
let mut i = 0;
for it.advance |&x: &uint| {
for it.advance |&x| {
assert_eq!(x, expected[i]);
i += 1;
}
@ -896,7 +900,7 @@ mod tests {
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: uint| {
for it.advance |x| {
assert_eq!(x, expected[i]);
i += 1;
}
@ -906,7 +910,7 @@ mod tests {
#[test]
fn test_filter_map() {
let mut it = Counter::new(0u, 1u).take(10)
.filter_map(|x: uint| if x.is_even() { Some(x*x) } else { None });
.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]);
}
@ -914,7 +918,7 @@ mod tests {
fn test_iterator_enumerate() {
let xs = [0u, 1, 2, 3, 4, 5];
let mut it = xs.iter().enumerate();
for it.advance |(i, &x): (uint, &uint)| {
for it.advance |(i, &x)| {
assert_eq!(i, x);
}
}
@ -925,7 +929,7 @@ mod tests {
let ys = [0u, 1, 2, 3, 5, 13];
let mut it = xs.iter().take_while(|&x| *x < 15u);
let mut i = 0;
for it.advance |&x: &uint| {
for it.advance |&x| {
assert_eq!(x, ys[i]);
i += 1;
}
@ -938,7 +942,7 @@ mod tests {
let ys = [15, 16, 17, 19];
let mut it = xs.iter().skip_while(|&x| *x < 15u);
let mut i = 0;
for it.advance |&x: &uint| {
for it.advance |&x| {
assert_eq!(x, ys[i]);
i += 1;
}
@ -1022,8 +1026,8 @@ mod tests {
#[test]
fn test_iterator_last() {
let v = &[0, 1, 2, 3, 4];
assert_eq!(v.iter().last().unwrap(), &4);
assert_eq!(v.slice(0, 1).iter().last().unwrap(), &0);
assert_eq!(v.iter().last_().unwrap(), &4);
assert_eq!(v.slice(0, 1).iter().last_().unwrap(), &0);
}
#[test]

View File

@ -87,6 +87,7 @@ bounded and unbounded protocols allows for less code duplication.
use container::Container;
use cast::{forget, transmute, transmute_copy};
use either::{Either, Left, Right};
use iterator::IteratorUtil;
use kinds::Owned;
use libc;
use ops::Drop;
@ -96,8 +97,7 @@ use unstable::intrinsics;
use ptr;
use ptr::RawPtr;
use task;
use vec;
use vec::OwnedVector;
use vec::{OwnedVector, MutableVector};
use util::replace;
static SPIN_COUNT: uint = 0;
@ -600,7 +600,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
let mut data_avail = false;
let mut ready_packet = pkts.len();
for vec::eachi_mut(pkts) |i, p| {
for pkts.mut_iter().enumerate().advance |(i, p)| {
unsafe {
let p = &mut *p.header();
let old = p.mark_blocked(this);
@ -622,7 +622,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
let event = wait_event(this) as *PacketHeader;
let mut pos = None;
for vec::eachi_mut(pkts) |i, p| {
for pkts.mut_iter().enumerate().advance |(i, p)| {
if p.header() == event {
pos = Some(i);
break;
@ -640,7 +640,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
debug!("%?", &mut pkts[ready_packet]);
for vec::each_mut(pkts) |p| {
for pkts.mut_iter().advance |p| {
unsafe {
(*p.header()).unblock()
}
@ -853,7 +853,7 @@ pub fn select<T:Owned,Tb:Owned>(mut endpoints: ~[RecvPacketBuffered<T, Tb>])
Option<T>,
~[RecvPacketBuffered<T, Tb>]) {
let mut endpoint_headers = ~[];
for vec::each_mut(endpoints) |endpoint| {
for endpoints.mut_iter().advance |endpoint| {
endpoint_headers.push(endpoint.header());
}

View File

@ -82,4 +82,3 @@ pub use io::{Reader, ReaderUtil, Writer, WriterUtil};
// Reexported runtime types
pub use comm::{stream, Port, Chan, GenericChan, GenericSmartChan, GenericPort, Peekable};
pub use task::spawn;

View File

@ -11,6 +11,7 @@
//! An ordered map and set for integer keys implemented as a radix trie
use prelude::*;
use iterator::IteratorUtil;
use uint;
use util::{swap, replace};
use vec;
@ -277,7 +278,7 @@ impl<T> TrieNode<T> {
}
fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
for vec::each_mut(self.children) |child| {
for self.children.mut_iter().advance |child| {
match *child {
Internal(ref mut x) => if !x.mutate_values(f) {
return false

View File

@ -19,7 +19,7 @@ use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
use clone::Clone;
use old_iter::BaseIter;
use old_iter;
use iterator::Iterator;
use iterator::{Iterator, IteratorUtil};
use iter::FromIter;
use kinds::Copy;
use libc;
@ -1568,28 +1568,6 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
return !broke;
}
/// Like `each()`, but for the case where you have
/// a vector with mutable contents and you would like
/// to mutate the contents as you iterate.
#[inline(always)]
pub fn each_mut<'r,T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) -> bool {
let mut broke = false;
do as_mut_buf(v) |p, n| {
let mut n = n;
let mut p = p;
while n > 0 {
unsafe {
let q: &'r mut T = cast::transmute_mut_region(&mut *p);
if !f(q) { break; }
p = p.offset(1);
}
n -= 1;
}
broke = n > 0;
}
return !broke;
}
/// Like `each()`, but for the case where you have a vector that *may or may
/// not* have mutable contents.
#[inline(always)]
@ -1620,24 +1598,6 @@ pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool {
return true;
}
/**
* Iterates over a mutable vector's elements and indices
*
* Return true to continue, false to break.
*/
#[inline(always)]
pub fn eachi_mut<'r,T>(v: &'r mut [T],
f: &fn(uint, v: &'r mut T) -> bool) -> bool {
let mut i = 0;
for each_mut(v) |p| {
if !f(i, p) {
return false;
}
i += 1;
}
return true;
}
/**
* Iterates over a vector's elements in reverse
*
@ -1666,44 +1626,6 @@ pub fn eachi_reverse<'r,T>(v: &'r [T],
return true;
}
/**
* Iterates over two vectors simultaneously
*
* # Failure
*
* Both vectors must have the same length
*/
#[inline]
pub fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool {
assert_eq!(v1.len(), v2.len());
for uint::range(0u, v1.len()) |i| {
if !f(&v1[i], &v2[i]) {
return false;
}
}
return true;
}
/**
*
* Iterates over two vector with mutable.
*
* # Failure
*
* Both vectors must have the same length
*/
#[inline]
pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T],
f: &fn(u: &mut U, t: &mut T) -> bool) -> bool {
assert_eq!(v1.len(), v2.len());
for uint::range(0u, v1.len()) |i| {
if !f(&mut v1[i], &mut v2[i]) {
return false;
}
}
return true;
}
/**
* Iterate over all permutations of vector `v`.
*
@ -2738,7 +2660,7 @@ impl<A> old_iter::BaseIter<A> for @[A] {
impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
#[inline(always)]
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) -> bool {
each_mut(*self, blk)
self.mut_iter().advance(blk)
}
}
@ -2746,7 +2668,7 @@ impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
impl<A> old_iter::MutableIter<A> for ~[A] {
#[inline(always)]
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) -> bool {
each_mut(*self, blk)
self.mut_iter().advance(blk)
}
}
@ -2754,7 +2676,7 @@ impl<A> old_iter::MutableIter<A> for ~[A] {
impl<A> old_iter::MutableIter<A> for @mut [A] {
#[inline(always)]
fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool) -> bool {
each_mut(*self, blk)
self.mut_iter().advance(blk)
}
}
@ -2786,7 +2708,7 @@ impl<'self,A> old_iter::ExtendedIter<A> for &'self [A] {
impl<'self,A> old_iter::ExtendedMutableIter<A> for &'self mut [A] {
#[inline(always)]
pub fn eachi_mut(&mut self, blk: &fn(uint, v: &mut A) -> bool) -> bool {
eachi_mut(*self, blk)
self.mut_iter().enumerate().advance(|(i, v)| blk(i, v))
}
}
@ -3646,16 +3568,13 @@ mod tests {
fn test_each_ret_len0() {
let mut a0 : [int, .. 0] = [];
assert_eq!(each(a0, |_p| fail!()), true);
assert_eq!(each_mut(a0, |_p| fail!()), true);
}
#[test]
fn test_each_ret_len1() {
let mut a1 = [17];
assert_eq!(each(a1, |_p| true), true);
assert_eq!(each_mut(a1, |_p| true), true);
assert_eq!(each(a1, |_p| false), false);
assert_eq!(each_mut(a1, |_p| false), false);
}

View File

@ -174,6 +174,7 @@ use opt_vec;
use core::uint;
use core::vec;
use core::iterator::IteratorUtil;
pub use self::ty::*;
mod ty;
@ -616,7 +617,7 @@ impl<'self> MethodDef<'self> {
// make a series of nested matches, to destructure the
// structs. This is actually right-to-left, but it shoudn't
// matter.
for vec::each2(self_args, patterns) |&arg_expr, &pat| {
for self_args.iter().zip(patterns.iter()).advance |(&arg_expr, &pat)| {
body = cx.expr_match(span, arg_expr,
~[ cx.arm(span, ~[pat], body) ])
}
@ -951,7 +952,7 @@ fn create_struct_pattern(cx: @ExtCtxt,
// must be nonempty to reach here
let pattern = if struct_type == Record {
let field_pats = do vec::build |push| {
for vec::each2(subpats, ident_expr) |&pat, &(id, _)| {
for subpats.iter().zip(ident_expr.iter()).advance |(&pat, &(id, _))| {
// id is guaranteed to be Some
push(ast::field_pat { ident: id.get(), pat: pat })
}

View File

@ -23,6 +23,7 @@ use ext::quote::rt::*;
use opt_vec;
use opt_vec::OptVec;
use core::iterator::IteratorUtil;
use core::str;
use core::vec;
@ -258,8 +259,7 @@ impl to_type_decls for state {
let mut items = ~[];
{
let messages = &mut *self.messages;
for vec::each_mut(*messages) |m| {
for self.messages.mut_iter().advance |m| {
if dir == send {
items.push(m.gen_send(cx, true));
items.push(m.gen_send(cx, false));

View File

@ -22,6 +22,7 @@ use parse::parser::Parser;
use parse::token::{Token, EOF, to_str, nonterminal, get_ident_interner, ident_to_str};
use parse::token;
use core::iterator::IteratorUtil;
use core::hashmap::HashMap;
use core::str;
use core::uint;
@ -358,7 +359,7 @@ pub fn parse(
if tok == EOF {
if eof_eis.len() == 1u {
let mut v = ~[];
for vec::each_mut(eof_eis[0u].matches) |dv| {
for eof_eis[0u].matches.mut_iter().advance |dv| {
v.push(dv.pop());
}
return success(nameize(sess, ms, v));

View File

@ -1,3 +1,4 @@
use std::iterator::*;
use std::from_str::FromStr;
use std::i32::range;
use std::os;
@ -29,9 +30,8 @@ fn fannkuch_redux(n: i32) -> i32 {
r -= 1;
}
// XXX: Need each2_mut.
for vec::eachi_mut(perm) |i, perm_i| {
*perm_i = perm1.unsafe_get(i);
for perm.mut_iter().zip(perm1.iter()).advance |(perm_i, perm1_i)| {
*perm_i = *perm1_i;
}
let mut flips_count: i32 = 0;

View File

@ -1,3 +1,4 @@
use std::iterator::IteratorUtil;
use std::cast::transmute;
use std::from_str::FromStr;
use std::libc::{FILE, STDOUT_FILENO, c_int, fdopen, fputc, fputs, fwrite, size_t};
@ -134,7 +135,7 @@ impl RandomFasta {
fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
let mut j = 0;
for vec::eachi_mut(lookup) |i, slot| {
for lookup.mut_iter().enumerate().advance |(i, slot)| {
while a[j].p < (i as f32) {
j += 1;
}

View File

@ -1,3 +1,4 @@
use std::iterator::IteratorUtil;
use std::f64;
use std::from_str::FromStr;
use std::os;
@ -104,7 +105,7 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
}
}
for vec::each_mut(*bodies) |a| {
for bodies.mut_iter().advance |a| {
a.x[0] += dt * a.v[0];
a.x[1] += dt * a.v[1];
a.x[2] += dt * a.v[2];

View File

@ -1,3 +1,4 @@
use std::iterator::IteratorUtil;
use std::f64;
use std::from_str::FromStr;
use std::iter::ExtendedMutableIter;
@ -18,9 +19,9 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
}
fn mult_Av(v: &mut [f64], out: &mut [f64]) {
for vec::eachi_mut(out) |i, out_i| {
for out.mut_iter().enumerate().advance |(i, out_i)| {
let mut sum = 0.0;
for vec::eachi_mut(v) |j, &v_j| {
for v.mut_iter().enumerate().advance |(j, &v_j)| {
sum += v_j / (A(i as i32, j as i32) as f64);
}
*out_i = sum;
@ -28,9 +29,9 @@ fn mult_Av(v: &mut [f64], out: &mut [f64]) {
}
fn mult_Atv(v: &mut [f64], out: &mut [f64]) {
for vec::eachi_mut(out) |i, out_i| {
for out.mut_iter().enumerate().advance |(i, out_i)| {
let mut sum = 0.0;
for vec::eachi_mut(v) |j, &v_j| {
for v.mut_iter().enumerate().advance |(j, &v_j)| {
sum += v_j / (A(j as i32, i as i32) as f64);
}
*out_i = sum;

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::vec;
use std::iterator::IteratorUtil;
fn test1() {
let mut ints = [0, ..32];
@ -18,7 +18,7 @@ fn test1() {
fn test2() {
let mut ints = [0, ..32];
for vec::each_mut(ints) |i| { *i += 22; }
for ints.mut_iter().advance |i| { *i += 22; }
for ints.each |i| { assert!(*i == 22); }
}

View File

@ -1,42 +0,0 @@
// 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.
// -*- rust -*-
use std::io;
use std::vec;
fn main(){
let mut t1 = ~[];
t1.push('a');
let mut t2 = ~[];
t2.push('b');
for vec::each2_mut(t1, t2) | i1, i2 | {
assert_eq!(*i1, 'a');
assert_eq!(*i2, 'b');
}
for vec::each2(t1, t2) | i1, i2 | {
io::println(fmt!("after t1: %?, t2: %?", i1, i2));
}
for vec::each2_mut(t1, t2) | i1, i2 | {
*i1 = 'b';
*i2 = 'a';
assert_eq!(*i1, 'b');
assert_eq!(*i2, 'a');
}
for vec::each2(t1, t2) | i1, i2 | {
io::println(fmt!("before t1: %?, t2: %?", i1, i2));
}
}