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());
}
playground
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.
This code leads to an out of bounds write, makes the assert fail and triggers miri:
playground
The problem is that after cloning a
Peekablethe inner iterator can no longer be considered advanced, but thePeekablemay still yield the peeked element without advancing it, thus breaking the contract ofInPlaceIterable.