Resolve FIXME and cleanup

This commit is contained in:
Shotaro Yamada 2018-12-08 20:15:49 +09:00
parent fbe5aa57ed
commit e704ce9e8a
2 changed files with 8 additions and 20 deletions

View File

@ -1868,18 +1868,11 @@ impl<I: Iterator> Iterator for Peekable<I> {
#[inline]
fn nth(&mut self, n: usize) -> Option<I::Item> {
// FIXME(#43234): merge these when borrow-checking gets better.
if n == 0 {
match self.peeked.take() {
Some(v) => v,
None => self.iter.nth(n),
}
} else {
match self.peeked.take() {
Some(None) => None,
Some(Some(_)) => self.iter.nth(n - 1),
None => self.iter.nth(n),
}
match self.peeked.take() {
Some(None) => None,
Some(v @ Some(_)) if n == 0 => v,
Some(Some(_)) => self.iter.nth(n - 1),
None => self.iter.nth(n),
}
}
@ -1978,14 +1971,8 @@ impl<I: Iterator> Peekable<I> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn peek(&mut self) -> Option<&I::Item> {
if self.peeked.is_none() {
self.peeked = Some(self.iter.next());
}
match self.peeked {
Some(Some(ref value)) => Some(value),
Some(None) => None,
_ => unreachable!(),
}
let iter = &mut self.iter;
self.peeked.get_or_insert_with(|| iter.next()).as_ref()
}
}

View File

@ -92,6 +92,7 @@
#![feature(link_llvm_intrinsics)]
#![feature(never_type)]
#![feature(nll)]
#![feature(bind_by_move_pattern_guards)]
#![feature(exhaustive_patterns)]
#![feature(no_core)]
#![feature(on_unimplemented)]