Closed
Description
struct S(bool);
impl Iterator for S {
type Item = ();
fn next(&mut self) -> Option<()> {
self.0 = !self.0;
if self.0 {
Some(())
} else {
None
}
}
}
impl std::iter::FusedIterator for S {}
fn main() {
let mut x = S(false).fuse();
for _i in &mut x {}
// x is fused, so it must be empty.
assert_eq!(x.next(), None);
}
This means unsafe code may not rely on iter.fuse()
to actually fuse the iterator if iter
is generic, which is unexpected to me.
I personally would like us to either add a note to Iterator::fuse
mentioning this or to remove the specialization for std::iter::Fused
.