You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today, I just got a huge problem internally in one of my crate. The bug is that the call to iterator.by_ref mutates/advances the iterator itself internally and that caused one of my software dependent on that carate to fail with an internal weird panic.
Borrows an iterator, rather than consuming it.
This is useful to allow applying iterator adapters while still retaining ownership of the original iterator.
From this text it's not clear that using this function still mutates/advances the internal iterator, so calling count for example is still gonna put the iterator to the end and will break all subsequent calls, essentially ending in weird cases where somehow the number of items is 1 but the later call to last().unwrap() panics!
The text was updated successfully, but these errors were encountered:
While you might be right this text is not clear (which I do not agree), the example clearly shows that the internal iterator still advances.
GuillaumeGomez
added
the
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
label
Mar 27, 2022
Today, I just got a huge problem internally in one of my crate. The bug is that the call to
iterator.by_ref
mutates/advances the iterator itself internally and that caused one of my software dependent on that carate to fail with an internal weird panic.On the following documentation link: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.by_ref the behavior of the function is not very clear.
The doc currently reads:
From this text it's not clear that using this function still mutates/advances the internal iterator, so calling count for example is still gonna put the iterator to the end and will break all subsequent calls, essentially ending in weird cases where somehow the number of items is 1 but the later call to
last().unwrap()
panics!The text was updated successfully, but these errors were encountered: