Closed
Description
This code leads to an out of bounds write, makes the assert fail and triggers miri:
fn main() {
let v = vec![0; 5];
let mut i = v.into_iter().peekable();
i.peek();
let v = i.clone().collect::<Vec<_>>();
assert!(v.len() <= v.capacity());
}
The problem is that after cloning a Peekable
the inner iterator can no longer be considered advanced, but the Peekable
may still yield the peeked element without advancing it, thus breaking the contract of InPlaceIterable
.