From bc3618e5c007e69e6b21b2aa4d2aad110da6655e Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Fri, 2 Dec 2016 21:13:57 +0100 Subject: [PATCH] core: Remove Self: Sized from Iterator::nth It is an unnecessary restriction; nth neither needs self to be sized nor needs to be exempted from the trait object. It increases the utility of the nth method, because type specific implementations are available through `&mut I` or through an iterator trait object. It is a backwards compatible change due to the special cases of the `where Self: Sized` bound; it was already optional to include this bound in `Iterator` implementations. --- src/liballoc/boxed.rs | 3 +++ src/libcore/iter/iterator.rs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 28f4dda140883..d10d7a5e58d65 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -524,6 +524,9 @@ impl Iterator for Box { fn size_hint(&self) -> (usize, Option) { (**self).size_hint() } + fn nth(&mut self, n: usize) -> Option { + (**self).nth(n) + } } #[stable(feature = "rust1", since = "1.0.0")] impl DoubleEndedIterator for Box { diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index f6b74a91c193b..48808b601c10c 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -247,7 +247,7 @@ pub trait Iterator { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn nth(&mut self, mut n: usize) -> Option where Self: Sized { + fn nth(&mut self, mut n: usize) -> Option { for x in self { if n == 0 { return Some(x) } n -= 1; @@ -2179,4 +2179,7 @@ impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I { type Item = I::Item; fn next(&mut self) -> Option { (**self).next() } fn size_hint(&self) -> (usize, Option) { (**self).size_hint() } + fn nth(&mut self, n: usize) -> Option { + (**self).nth(n) + } }