Skip to content

workaround to land #6995 #6999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libextra/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use core::prelude::*;

use core::iterator::IteratorUtil;
use core::str;
use core::uint;
use core::vec;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use core::prelude::*;

use core::iterator::IteratorUtil;
use core::cast;
use core::io;
use core::str;
Expand Down Expand Up @@ -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]) {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/trans/type_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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| {
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/typeck/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
48 changes: 26 additions & 22 deletions src/libstd/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}
}

Expand All @@ -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}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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()) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -906,15 +910,15 @@ 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]);
}

#[test]
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);
}
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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]
Expand Down
Loading