From cef45b3baf3593401657f9f40c7c9b08b57a251f Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 18 Nov 2017 03:45:51 -0800 Subject: [PATCH] Undo the Sized specialization from Iterator::nth --- src/libcore/iter/iterator.rs | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 6a4dba31b62..40298389c1a 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -253,8 +253,12 @@ fn last(self) -> Option where Self: Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn nth(&mut self, n: usize) -> Option { - self.spec_nth(n) + fn nth(&mut self, mut n: usize) -> Option { + 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).nth(n) } } - - -trait SpecIterator : Iterator { - fn spec_nth(&mut self, n: usize) -> Option; -} - -impl SpecIterator for I { - default fn spec_nth(&mut self, mut n: usize) -> Option { - for x in self { - if n == 0 { return Some(x) } - n -= 1; - } - None - } -} - -impl SpecIterator for I { - fn spec_nth(&mut self, n: usize) -> Option { - self.try_fold(n, move |i, x| { - if i == 0 { LoopState::Break(x) } - else { LoopState::Continue(i - 1) } - }).break_value() - } -} -- 2.44.0