]> git.lizzy.rs Git - rust.git/commitdiff
Undo the Sized specialization from Iterator::nth
authorScott McMurray <scottmcm@users.noreply.github.com>
Sat, 18 Nov 2017 11:45:51 +0000 (03:45 -0800)
committerScott McMurray <scottmcm@users.noreply.github.com>
Sat, 18 Nov 2017 11:45:51 +0000 (03:45 -0800)
src/libcore/iter/iterator.rs

index 6a4dba31b62a926a09c959cd17d3aa294899feb5..40298389c1ac7d8da4bb754f1e2a6579d01593fd 100644 (file)
@@ -253,8 +253,12 @@ fn last(self) -> Option<Self::Item> where Self: Sized {
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
-    fn nth(&mut self, n: usize) -> Option<Self::Item> {
-        self.spec_nth(n)
+    fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
+        for x in self {
+            if n == 0 { return Some(x) }
+            n -= 1;
+        }
+        None
     }
 
     /// Creates an iterator starting at the same point, but stepping by
@@ -2381,27 +2385,3 @@ fn nth(&mut self, n: usize) -> Option<Self::Item> {
         (**self).nth(n)
     }
 }
-
-
-trait SpecIterator : Iterator {
-    fn spec_nth(&mut self, n: usize) -> Option<Self::Item>;
-}
-
-impl<I: Iterator + ?Sized> SpecIterator for I {
-    default fn spec_nth(&mut self, mut n: usize) -> Option<Self::Item> {
-        for x in self {
-            if n == 0 { return Some(x) }
-            n -= 1;
-        }
-        None
-   }
-}
-
-impl<I: Iterator + Sized> SpecIterator for I {
-    fn spec_nth(&mut self, n: usize) -> Option<Self::Item> {
-        self.try_fold(n, move |i, x| {
-            if i == 0 { LoopState::Break(x) }
-            else { LoopState::Continue(i - 1) }
-        }).break_value()
-   }
-}