From 5e9f006c5b95ea98893b0398decd458fd642f38f Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 7 Jun 2013 23:42:35 +1000 Subject: [PATCH] std: more dummy type parameters on iterators to work around #6967. --- src/libstd/iterator.rs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 7f723e44c2b..4bc545f607d 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -55,7 +55,7 @@ pub trait IteratorUtil { /// assert_eq!(it.next().get(), &1); /// assert!(it.next().is_none()); /// ~~~ - fn chain>(self, other: U) -> ChainIterator; + fn chain>(self, other: U) -> ChainIterator; /// 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 { /// assert_eq!(it.next().get(), (&0, &1)); /// assert!(it.next().is_none()); /// ~~~ - fn zip>(self, other: U) -> ZipIterator; + fn zip>(self, other: U) -> ZipIterator; // 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 { /// assert_eq!(it.next().get(), (1, &200)); /// assert!(it.next().is_none()); /// ~~~ - fn enumerate(self) -> EnumerateIterator; + fn enumerate(self) -> EnumerateIterator; /// Creates an iterator which invokes the predicate on elements until it /// returns true. Once the predicate returns true, all further elements are @@ -349,12 +349,12 @@ pub trait IteratorUtil { /// In the future these will be default methods instead of a utility trait. impl> IteratorUtil for T { #[inline(always)] - fn chain>(self, other: U) -> ChainIterator { + fn chain>(self, other: U) -> ChainIterator { ChainIterator{a: self, b: other, flag: false} } #[inline(always)] - fn zip>(self, other: U) -> ZipIterator { + fn zip>(self, other: U) -> ZipIterator { ZipIterator{a: self, b: other} } @@ -375,7 +375,7 @@ impl> IteratorUtil for T { } #[inline(always)] - fn enumerate(self) -> EnumerateIterator { + fn enumerate(self) -> EnumerateIterator { EnumerateIterator{iter: self, count: 0} } @@ -570,13 +570,14 @@ impl> OrdIterator for T { } /// An iterator which strings two iterators together -pub struct ChainIterator { +// FIXME #6967: Dummy A parameter to get around type inference bug +pub struct ChainIterator { priv a: T, priv b: U, priv flag: bool } -impl, U: Iterator> Iterator for ChainIterator { +impl, U: Iterator> Iterator for ChainIterator { #[inline] fn next(&mut self) -> Option { if self.flag { @@ -593,12 +594,13 @@ impl, U: Iterator> Iterator for ChainIterator { } /// An iterator which iterates two other iterators simultaneously -pub struct ZipIterator { +// FIXME #6967: Dummy A & B parameters to get around type inference bug +pub struct ZipIterator { priv a: T, priv b: U } -impl, U: Iterator> Iterator<(A, B)> for ZipIterator { +impl, U: Iterator> Iterator<(A, B)> for ZipIterator { #[inline] fn next(&mut self) -> Option<(A, B)> { match (self.a.next(), self.b.next()) { @@ -664,12 +666,13 @@ impl<'self, A, B, T: Iterator> Iterator for FilterMapIterator<'self, A, B, } /// An iterator which yields the current count and the element during iteration -pub struct EnumerateIterator { +// FIXME #6967: Dummy A parameter to get around type inference bug +pub struct EnumerateIterator { priv iter: T, priv count: uint } -impl> Iterator<(uint, A)> for EnumerateIterator { +impl> Iterator<(uint, A)> for EnumerateIterator { #[inline] fn next(&mut self) -> Option<(uint, A)> { match self.iter.next() { @@ -887,7 +890,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 +899,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 +909,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 +917,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 +928,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 +941,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; }