Skip to content

Commit d8d5b61

Browse files
committed
Auto merge of rust-lang#46074 - scottmcm:unspecialize-nth, r=bluss
Undo the Sized specialization from Iterator::nth I just added this as part of rust-lang#45595, but I'm now afraid there's a specialization issue with it, since I tried to add [another similar specialization](https://github.com/rust-lang/rust/compare/master...scottmcm:faster-iter-by-ref?expand=1#diff-1398f322bc563592215b583e9b0ba936R2390), and ended up getting really disturbing test failures like ``` thread 'iter::test_by_ref_folds' panicked at 'assertion failed: `(left == right)` left: `15`, right: `15`', src\libcore\../libcore/tests\iter.rs:1720:4 ``` So since this wasn't the most critical part of the change and a new beta is branching within a week, I think putting this part back to what it was before is the best option.
2 parents c5c70ef + cef45b3 commit d8d5b61

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

Diff for: src/libcore/iter/iterator.rs

+6-26
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,12 @@ pub trait Iterator {
253253
/// ```
254254
#[inline]
255255
#[stable(feature = "rust1", since = "1.0.0")]
256-
fn nth(&mut self, n: usize) -> Option<Self::Item> {
257-
self.spec_nth(n)
256+
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
257+
for x in self {
258+
if n == 0 { return Some(x) }
259+
n -= 1;
260+
}
261+
None
258262
}
259263

260264
/// Creates an iterator starting at the same point, but stepping by
@@ -2381,27 +2385,3 @@ impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
23812385
(**self).nth(n)
23822386
}
23832387
}
2384-
2385-
2386-
trait SpecIterator : Iterator {
2387-
fn spec_nth(&mut self, n: usize) -> Option<Self::Item>;
2388-
}
2389-
2390-
impl<I: Iterator + ?Sized> SpecIterator for I {
2391-
default fn spec_nth(&mut self, mut n: usize) -> Option<Self::Item> {
2392-
for x in self {
2393-
if n == 0 { return Some(x) }
2394-
n -= 1;
2395-
}
2396-
None
2397-
}
2398-
}
2399-
2400-
impl<I: Iterator + Sized> SpecIterator for I {
2401-
fn spec_nth(&mut self, n: usize) -> Option<Self::Item> {
2402-
self.try_fold(n, move |i, x| {
2403-
if i == 0 { LoopState::Break(x) }
2404-
else { LoopState::Continue(i - 1) }
2405-
}).break_value()
2406-
}
2407-
}

0 commit comments

Comments
 (0)