Skip to content

Commit 32228f3

Browse files
committed
std: work-around for take/skip type inference (#6967)
1 parent 7e62ad6 commit 32228f3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/libstd/iterator.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub trait IteratorUtil<A> {
186186
/// assert_eq!(it.next().get(), &5);
187187
/// assert!(it.next().is_none());
188188
/// ~~~
189-
fn skip(self, n: uint) -> SkipIterator<Self>;
189+
fn skip(self, n: uint) -> SkipIterator<A, Self>;
190190

191191
/// Creates an iterator which yields the first `n` elements of this
192192
/// iterator, and then it will always return None.
@@ -203,7 +203,7 @@ pub trait IteratorUtil<A> {
203203
/// assert_eq!(it.next().get(), &3);
204204
/// assert!(it.next().is_none());
205205
/// ~~~
206-
fn take(self, n: uint) -> TakeIterator<Self>;
206+
fn take(self, n: uint) -> TakeIterator<A, Self>;
207207

208208
/// Creates a new iterator which behaves in a similar fashion to foldl.
209209
/// There is a state which is passed between each iteration and can be
@@ -386,12 +386,12 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
386386
}
387387

388388
#[inline(always)]
389-
fn skip(self, n: uint) -> SkipIterator<T> {
389+
fn skip(self, n: uint) -> SkipIterator<A, T> {
390390
SkipIterator{iter: self, n: n}
391391
}
392392

393393
#[inline(always)]
394-
fn take(self, n: uint) -> TakeIterator<T> {
394+
fn take(self, n: uint) -> TakeIterator<A, T> {
395395
TakeIterator{iter: self, n: n}
396396
}
397397

@@ -739,13 +739,14 @@ impl<'self, A, T: Iterator<A>> Iterator<A> for TakeWhileIterator<'self, A, T> {
739739
}
740740
}
741741

742-
/// An iterator which skips over `n` elements of `iter`
743-
pub struct SkipIterator<T> {
742+
/// An iterator which skips over `n` elements of `iter`.
743+
// FIXME #6967: Dummy A parameter to get around type inference bug
744+
pub struct SkipIterator<A, T> {
744745
priv iter: T,
745746
priv n: uint
746747
}
747748

748-
impl<A, T: Iterator<A>> Iterator<A> for SkipIterator<T> {
749+
impl<A, T: Iterator<A>> Iterator<A> for SkipIterator<A, T> {
749750
#[inline]
750751
fn next(&mut self) -> Option<A> {
751752
let mut next = self.iter.next();
@@ -772,12 +773,13 @@ impl<A, T: Iterator<A>> Iterator<A> for SkipIterator<T> {
772773
}
773774

774775
/// An iterator which only iterates over the first `n` iterations of `iter`.
775-
pub struct TakeIterator<T> {
776+
// FIXME #6967: Dummy A parameter to get around type inference bug
777+
pub struct TakeIterator<A, T> {
776778
priv iter: T,
777779
priv n: uint
778780
}
779781

780-
impl<A, T: Iterator<A>> Iterator<A> for TakeIterator<T> {
782+
impl<A, T: Iterator<A>> Iterator<A> for TakeIterator<A, T> {
781783
#[inline]
782784
fn next(&mut self) -> Option<A> {
783785
let next = self.iter.next();
@@ -945,7 +947,7 @@ mod tests {
945947
let ys = [13, 15, 16, 17, 19, 20, 30];
946948
let mut it = xs.iter().skip(5);
947949
let mut i = 0;
948-
for it.advance |&x: &uint| {
950+
for it.advance |&x| {
949951
assert_eq!(x, ys[i]);
950952
i += 1;
951953
}
@@ -958,7 +960,7 @@ mod tests {
958960
let ys = [0u, 1, 2, 3, 5];
959961
let mut it = xs.iter().take(5);
960962
let mut i = 0;
961-
for it.advance |&x: &uint| {
963+
for it.advance |&x| {
962964
assert_eq!(x, ys[i]);
963965
i += 1;
964966
}

0 commit comments

Comments
 (0)