Skip to content

Commit b8cf2f8

Browse files
committed
auto merge of #6999 : thestinger/rust/each-fn-kill, r=thestinger
2 parents 18019a1 + 07e4d69 commit b8cf2f8

22 files changed

+82
-188
lines changed

src/libextra/sha1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use core::prelude::*;
2626

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

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use core::prelude::*;
2020

21+
use core::iterator::IteratorUtil;
2122
use core::cast;
2223
use core::io;
2324
use core::str;
@@ -895,7 +896,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
895896

896897
fn reset(&mut self, bits: &mut [uint]) {
897898
let e = if self.dfcx.oper.initial_value() {uint::max_value} else {0};
898-
for vec::each_mut(bits) |b| { *b = e; }
899+
for bits.mut_iter().advance |b| { *b = e; }
899900
}
900901

901902
fn add_to_entry_set(&mut self, id: ast::node_id, pred_bits: &[uint]) {

src/librustc/middle/kind.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use middle::typeck;
1717
use util::ppaux::{Repr, ty_to_str};
1818
use util::ppaux::UserString;
1919

20+
use core::iterator::IteratorUtil;
2021
use core::vec;
2122
use syntax::ast::*;
2223
use syntax::attr::attrs_contains_name;
@@ -268,7 +269,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
268269
ts.repr(cx.tcx),
269270
type_param_defs.repr(cx.tcx));
270271
}
271-
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
272+
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
272273
check_bounds(cx, type_parameter_id, e.span, ty, type_param_def)
273274
}
274275
}
@@ -309,7 +310,7 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
309310
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
310311
let type_param_defs =
311312
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
312-
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
313+
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
313314
check_bounds(cx, aty.id, aty.span, ty, type_param_def)
314315
}
315316
}

src/librustc/middle/trans/inline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use middle::trans::common::*;
1919
use middle::ty;
2020
use util::ppaux::ty_to_str;
2121

22+
use core::iterator::IteratorUtil;
2223
use core::vec;
2324
use syntax::ast;
2425
use syntax::ast_map::path_name;
@@ -75,7 +76,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id,
7576
ast::item_enum(_, _) => {
7677
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
7778
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
78-
for vec::each2(*vs_here, *vs_there) |here, there| {
79+
for vs_here.iter().zip(vs_there.iter()).advance |(here, there)| {
7980
if there.id == fn_id { my_id = here.id.node; }
8081
ccx.external.insert(there.id, Some(here.id.node));
8182
}

src/librustc/middle/trans/type_use.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use middle::trans::inline;
3333
use middle::ty;
3434
use middle::typeck;
3535

36+
use core::iterator::IteratorUtil;
3637
use core::option::{Some, None};
3738
use core::uint;
3839
use core::vec;
@@ -264,7 +265,7 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
264265
for opt_static_did.each |&did| {
265266
for cx.ccx.tcx.node_type_substs.find_copy(&callee_id).each |ts| {
266267
let type_uses = type_uses_for(cx.ccx, did, ts.len());
267-
for vec::each2(*type_uses, *ts) |uses, subst| {
268+
for type_uses.iter().zip(ts.iter()).advance |(uses, subst)| {
268269
type_needs(cx, *uses, *subst)
269270
}
270271
}
@@ -302,7 +303,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
302303
for opt_ts.each |ts| {
303304
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get_copy(&e.id));
304305
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
305-
for vec::each2(*uses_for_ts, *ts) |uses, subst| {
306+
for uses_for_ts.iter().zip(ts.iter()).advance |(uses, subst)| {
306307
type_needs(cx, *uses, *subst)
307308
}
308309
}

src/librustc/middle/typeck/check/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use middle::typeck::check::{instantiate_path, lookup_def};
1818
use middle::typeck::check::{structure_of, valid_range_bounds};
1919
use middle::typeck::require_same_types;
2020

21+
use core::iterator::IteratorUtil;
2122
use core::hashmap::{HashMap, HashSet};
22-
use core::vec;
2323
use syntax::ast;
2424
use syntax::ast_util;
2525
use syntax::codemap::span;
@@ -232,7 +232,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
232232
233233
if !error_happened {
234234
for subpats.each |pats| {
235-
for vec::each2(*pats, arg_types) |subpat, arg_ty| {
235+
for pats.iter().zip(arg_types.iter()).advance |(subpat, arg_ty)| {
236236
check_pat(pcx, *subpat, *arg_ty);
237237
}
238238
}

src/librustc/middle/typeck/check/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ use util::common::{block_query, indenter, loop_query};
110110
use util::ppaux::{bound_region_to_str};
111111
use util::ppaux;
112112

113+
114+
use core::iterator::IteratorUtil;
113115
use core::cast::transmute;
114116
use core::hashmap::HashMap;
115117
use core::result;
@@ -412,7 +414,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
412414
for opt_self_info.each |self_info| {
413415
fcx.write_ty(self_info.self_id, self_info.self_ty);
414416
}
415-
for vec::each2(decl.inputs, arg_tys) |input, arg| {
417+
for decl.inputs.iter().zip(arg_tys.iter()).advance |(input, arg)| {
416418
fcx.write_ty(input.id, *arg);
417419
}
418420

@@ -449,7 +451,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
449451
}
450452

451453
// Add formal parameters.
452-
for vec::each2(arg_tys, decl.inputs) |arg_ty, input| {
454+
for arg_tys.iter().zip(decl.inputs.iter()).advance |(arg_ty, input)| {
453455
// Create type variables for each argument.
454456
do pat_util::pat_bindings(tcx.def_map, input.pat)
455457
|_bm, pat_id, _sp, _path| {

src/librustc/middle/typeck/coherence.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ use syntax::visit::{Visitor, SimpleVisitor};
5454
use syntax::visit::{visit_mod};
5555
use util::ppaux::ty_to_str;
5656

57+
use core::iterator::IteratorUtil;
5758
use core::hashmap::{HashMap, HashSet};
5859
use core::old_iter;
5960
use core::result::Ok;
@@ -617,9 +618,9 @@ impl CoherenceChecker {
617618
// Check to ensure that each parameter binding respected its
618619
// kind bounds.
619620
for [ a, b ].each |result| {
620-
for vec::each2(result.type_variables,
621-
*result.type_param_defs)
622-
|ty_var, type_param_def|
621+
for result.type_variables.iter()
622+
.zip(result.type_param_defs.iter())
623+
.advance |(ty_var, type_param_def)|
623624
{
624625
if type_param_def.bounds.builtin_bounds.contains_elem(
625626
ty::BoundCopy)

src/libstd/iterator.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait IteratorUtil<A> {
5555
/// assert_eq!(it.next().get(), &1);
5656
/// assert!(it.next().is_none());
5757
/// ~~~
58-
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<Self, U>;
58+
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<A, Self, U>;
5959

6060
/// Creates an iterator which iterates over both this and the specified
6161
/// iterators simultaneously, yielding the two elements as pairs. When
@@ -73,7 +73,7 @@ pub trait IteratorUtil<A> {
7373
/// assert_eq!(it.next().get(), (&0, &1));
7474
/// assert!(it.next().is_none());
7575
/// ~~~
76-
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<Self, U>;
76+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<A, Self, B, U>;
7777

7878
// FIXME: #5898: should be called map
7979
/// Creates a new iterator which will apply the specified function to each
@@ -139,7 +139,7 @@ pub trait IteratorUtil<A> {
139139
/// assert_eq!(it.next().get(), (1, &200));
140140
/// assert!(it.next().is_none());
141141
/// ~~~
142-
fn enumerate(self) -> EnumerateIterator<Self>;
142+
fn enumerate(self) -> EnumerateIterator<A, Self>;
143143

144144
/// Creates an iterator which invokes the predicate on elements until it
145145
/// returns true. Once the predicate returns true, all further elements are
@@ -285,7 +285,8 @@ pub trait IteratorUtil<A> {
285285
/// let a = [1, 2, 3, 4, 5];
286286
/// assert!(a.iter().last().get() == &5);
287287
/// ~~~
288-
fn last(&mut self) -> Option<A>;
288+
// FIXME: #5898: should be called `last`
289+
fn last_(&mut self) -> Option<A>;
289290

290291
/// Performs a fold operation over the entire iterator, returning the
291292
/// eventual state at the end of the iteration.
@@ -349,12 +350,12 @@ pub trait IteratorUtil<A> {
349350
/// In the future these will be default methods instead of a utility trait.
350351
impl<A, T: Iterator<A>> IteratorUtil<A> for T {
351352
#[inline(always)]
352-
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<T, U> {
353+
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<A, T, U> {
353354
ChainIterator{a: self, b: other, flag: false}
354355
}
355356

356357
#[inline(always)]
357-
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
358+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<A, T, B, U> {
358359
ZipIterator{a: self, b: other}
359360
}
360361

@@ -375,7 +376,7 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
375376
}
376377

377378
#[inline(always)]
378-
fn enumerate(self) -> EnumerateIterator<T> {
379+
fn enumerate(self) -> EnumerateIterator<A, T> {
379380
EnumerateIterator{iter: self, count: 0}
380381
}
381382

@@ -437,7 +438,7 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
437438

438439
/// Return the last item yielded by an iterator.
439440
#[inline(always)]
440-
fn last(&mut self) -> Option<A> {
441+
fn last_(&mut self) -> Option<A> {
441442
let mut last = None;
442443
for self.advance |x| { last = Some(x); }
443444
last
@@ -570,13 +571,14 @@ impl<A: Ord, T: Iterator<A>> OrdIterator<A> for T {
570571
}
571572

572573
/// An iterator which strings two iterators together
573-
pub struct ChainIterator<T, U> {
574+
// FIXME #6967: Dummy A parameter to get around type inference bug
575+
pub struct ChainIterator<A, T, U> {
574576
priv a: T,
575577
priv b: U,
576578
priv flag: bool
577579
}
578580

579-
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
581+
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<A, T, U> {
580582
#[inline]
581583
fn next(&mut self) -> Option<A> {
582584
if self.flag {
@@ -593,12 +595,13 @@ impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
593595
}
594596

595597
/// An iterator which iterates two other iterators simultaneously
596-
pub struct ZipIterator<T, U> {
598+
// FIXME #6967: Dummy A & B parameters to get around type inference bug
599+
pub struct ZipIterator<A, T, B, U> {
597600
priv a: T,
598601
priv b: U
599602
}
600603

601-
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<T, U> {
604+
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<A, T, B, U> {
602605
#[inline]
603606
fn next(&mut self) -> Option<(A, B)> {
604607
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,
664667
}
665668

666669
/// An iterator which yields the current count and the element during iteration
667-
pub struct EnumerateIterator<T> {
670+
// FIXME #6967: Dummy A parameter to get around type inference bug
671+
pub struct EnumerateIterator<A, T> {
668672
priv iter: T,
669673
priv count: uint
670674
}
671675

672-
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<T> {
676+
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<A, T> {
673677
#[inline]
674678
fn next(&mut self) -> Option<(uint, A)> {
675679
match self.iter.next() {
@@ -887,7 +891,7 @@ mod tests {
887891
let expected = [0, 1, 2, 3, 4, 5, 30, 40, 50, 60];
888892
let mut it = xs.iter().chain(ys.iter());
889893
let mut i = 0;
890-
for it.advance |&x: &uint| {
894+
for it.advance |&x| {
891895
assert_eq!(x, expected[i]);
892896
i += 1;
893897
}
@@ -896,7 +900,7 @@ mod tests {
896900
let ys = Counter::new(30u, 10).take(4);
897901
let mut it = xs.iter().transform(|&x| x).chain(ys);
898902
let mut i = 0;
899-
for it.advance |x: uint| {
903+
for it.advance |x| {
900904
assert_eq!(x, expected[i]);
901905
i += 1;
902906
}
@@ -906,15 +910,15 @@ mod tests {
906910
#[test]
907911
fn test_filter_map() {
908912
let mut it = Counter::new(0u, 1u).take(10)
909-
.filter_map(|x: uint| if x.is_even() { Some(x*x) } else { None });
913+
.filter_map(|x| if x.is_even() { Some(x*x) } else { None });
910914
assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
911915
}
912916

913917
#[test]
914918
fn test_iterator_enumerate() {
915919
let xs = [0u, 1, 2, 3, 4, 5];
916920
let mut it = xs.iter().enumerate();
917-
for it.advance |(i, &x): (uint, &uint)| {
921+
for it.advance |(i, &x)| {
918922
assert_eq!(i, x);
919923
}
920924
}
@@ -925,7 +929,7 @@ mod tests {
925929
let ys = [0u, 1, 2, 3, 5, 13];
926930
let mut it = xs.iter().take_while(|&x| *x < 15u);
927931
let mut i = 0;
928-
for it.advance |&x: &uint| {
932+
for it.advance |&x| {
929933
assert_eq!(x, ys[i]);
930934
i += 1;
931935
}
@@ -938,7 +942,7 @@ mod tests {
938942
let ys = [15, 16, 17, 19];
939943
let mut it = xs.iter().skip_while(|&x| *x < 15u);
940944
let mut i = 0;
941-
for it.advance |&x: &uint| {
945+
for it.advance |&x| {
942946
assert_eq!(x, ys[i]);
943947
i += 1;
944948
}
@@ -1022,8 +1026,8 @@ mod tests {
10221026
#[test]
10231027
fn test_iterator_last() {
10241028
let v = &[0, 1, 2, 3, 4];
1025-
assert_eq!(v.iter().last().unwrap(), &4);
1026-
assert_eq!(v.slice(0, 1).iter().last().unwrap(), &0);
1029+
assert_eq!(v.iter().last_().unwrap(), &4);
1030+
assert_eq!(v.slice(0, 1).iter().last_().unwrap(), &0);
10271031
}
10281032

10291033
#[test]

0 commit comments

Comments
 (0)