Skip to content

Commit 5e9f006

Browse files
committed
std: more dummy type parameters on iterators to work around #6967.
1 parent 0d0c004 commit 5e9f006

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/libstd/iterator.rs

Lines changed: 21 additions & 18 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
@@ -349,12 +349,12 @@ pub trait IteratorUtil<A> {
349349
/// In the future these will be default methods instead of a utility trait.
350350
impl<A, T: Iterator<A>> IteratorUtil<A> for T {
351351
#[inline(always)]
352-
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<T, U> {
352+
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<A, T, U> {
353353
ChainIterator{a: self, b: other, flag: false}
354354
}
355355

356356
#[inline(always)]
357-
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
357+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<A, T, B, U> {
358358
ZipIterator{a: self, b: other}
359359
}
360360

@@ -375,7 +375,7 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
375375
}
376376

377377
#[inline(always)]
378-
fn enumerate(self) -> EnumerateIterator<T> {
378+
fn enumerate(self) -> EnumerateIterator<A, T> {
379379
EnumerateIterator{iter: self, count: 0}
380380
}
381381

@@ -570,13 +570,14 @@ impl<A: Ord, T: Iterator<A>> OrdIterator<A> for T {
570570
}
571571

572572
/// An iterator which strings two iterators together
573-
pub struct ChainIterator<T, U> {
573+
// FIXME #6967: Dummy A parameter to get around type inference bug
574+
pub struct ChainIterator<A, T, U> {
574575
priv a: T,
575576
priv b: U,
576577
priv flag: bool
577578
}
578579

579-
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
580+
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<A, T, U> {
580581
#[inline]
581582
fn next(&mut self) -> Option<A> {
582583
if self.flag {
@@ -593,12 +594,13 @@ impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
593594
}
594595

595596
/// An iterator which iterates two other iterators simultaneously
596-
pub struct ZipIterator<T, U> {
597+
// FIXME #6967: Dummy A & B parameters to get around type inference bug
598+
pub struct ZipIterator<A, T, B, U> {
597599
priv a: T,
598600
priv b: U
599601
}
600602

601-
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<T, U> {
603+
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<A, T, B, U> {
602604
#[inline]
603605
fn next(&mut self) -> Option<(A, B)> {
604606
match (self.a.next(), self.b.next()) {
@@ -664,12 +666,13 @@ impl<'self, A, B, T: Iterator<A>> Iterator<B> for FilterMapIterator<'self, A, B,
664666
}
665667

666668
/// An iterator which yields the current count and the element during iteration
667-
pub struct EnumerateIterator<T> {
669+
// FIXME #6967: Dummy A parameter to get around type inference bug
670+
pub struct EnumerateIterator<A, T> {
668671
priv iter: T,
669672
priv count: uint
670673
}
671674

672-
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<T> {
675+
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<A, T> {
673676
#[inline]
674677
fn next(&mut self) -> Option<(uint, A)> {
675678
match self.iter.next() {
@@ -887,7 +890,7 @@ mod tests {
887890
let expected = [0, 1, 2, 3, 4, 5, 30, 40, 50, 60];
888891
let mut it = xs.iter().chain(ys.iter());
889892
let mut i = 0;
890-
for it.advance |&x: &uint| {
893+
for it.advance |&x| {
891894
assert_eq!(x, expected[i]);
892895
i += 1;
893896
}
@@ -896,7 +899,7 @@ mod tests {
896899
let ys = Counter::new(30u, 10).take(4);
897900
let mut it = xs.iter().transform(|&x| x).chain(ys);
898901
let mut i = 0;
899-
for it.advance |x: uint| {
902+
for it.advance |x| {
900903
assert_eq!(x, expected[i]);
901904
i += 1;
902905
}
@@ -906,15 +909,15 @@ mod tests {
906909
#[test]
907910
fn test_filter_map() {
908911
let mut it = Counter::new(0u, 1u).take(10)
909-
.filter_map(|x: uint| if x.is_even() { Some(x*x) } else { None });
912+
.filter_map(|x| if x.is_even() { Some(x*x) } else { None });
910913
assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
911914
}
912915

913916
#[test]
914917
fn test_iterator_enumerate() {
915918
let xs = [0u, 1, 2, 3, 4, 5];
916919
let mut it = xs.iter().enumerate();
917-
for it.advance |(i, &x): (uint, &uint)| {
920+
for it.advance |(i, &x)| {
918921
assert_eq!(i, x);
919922
}
920923
}
@@ -925,7 +928,7 @@ mod tests {
925928
let ys = [0u, 1, 2, 3, 5, 13];
926929
let mut it = xs.iter().take_while(|&x| *x < 15u);
927930
let mut i = 0;
928-
for it.advance |&x: &uint| {
931+
for it.advance |&x| {
929932
assert_eq!(x, ys[i]);
930933
i += 1;
931934
}
@@ -938,7 +941,7 @@ mod tests {
938941
let ys = [15, 16, 17, 19];
939942
let mut it = xs.iter().skip_while(|&x| *x < 15u);
940943
let mut i = 0;
941-
for it.advance |&x: &uint| {
944+
for it.advance |&x| {
942945
assert_eq!(x, ys[i]);
943946
i += 1;
944947
}

0 commit comments

Comments
 (0)