Closed
Description
Testcase:
struct CrazyIterator(bool);
impl CrazyIterator { fn new() -> CrazyIterator { CrazyIterator(false) } }
impl Iterator for CrazyIterator {
type Item = i32;
fn next(&mut self) -> Option<i32> {
if self.0 { Some(1) } else { self.0 = true; None }
}
}
impl DoubleEndedIterator for CrazyIterator {
fn next_back(&mut self) -> Option<i32> {
self.next()
}
}
fn main() {
println!("{}", CrazyIterator::new().chain(0..10).rev().any(|i| i > 10i32));
println!("{}", (0..10).chain(CrazyIterator::new()).rev().any(|i| i > 10i32));
}
gives:
false
playpen: timeout triggered!
I'm pretty sure CrazyIterator isn't a legitimate implementation of DoubleEndedIterator, but the documentation doesn't say that explicitly, and it explicitly states that this is a legitimate implementation of Iterator. (If this is supposed to be allowed, std::iter::Chain has a bug.)