-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove drain-on-drop behavior from various DrainFilter iterators #136
Comments
Seconded. I think this is actually quite intuitive: only elements that are returned from the iterator are actually removed from the collection. |
I think renaming is a good idea, not least because the alternative is breaking people in a pretty subtle way as they upgrade their nightly version. (None of these are stable, right?) Is the recommended pattern if you want the old behavior something like .for_each(|_| {}) to preserve performance? Or is there something better? |
Correct.
For most collections there's a Only LinkedList doesn't have that. But there you can't do much better than |
Ah, I see. I guess we stabilized retain_mut on Vec too now. Still, the rename seems like a good idea to avoid future confusion and subtle breakage now, even if most users not actively iterating have a better path in retain today. |
Sure. Any preferences?
|
No particular preferences from me. |
This has been seconded and no objections have been registered, so I'm closing the issue as approved. |
Remove drain-on-drop behavior from DrainFilter This is a breaking change for hashbrown but not for std because in std the drain impl is still unstable. This is part of stdlib [ACP 136](rust-lang/libs-team#136).
Don't drain-on-drop in DrainFilter impls of various collections. This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](rust-lang#43244 (comment)) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](rust-lang/rfcs#3288). closes rust-lang#101122 [ACP](rust-lang/libs-team#136) affected tracking issues * rust-lang#43244 * rust-lang#70530 * rust-lang#59618 Related hashbrown update: rust-lang/hashbrown#374
Don't drain-on-drop in DrainFilter impls of various collections. This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](rust-lang/rust#43244 (comment)) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](rust-lang/rfcs#3288). closes #101122 [ACP](rust-lang/libs-team#136) affected tracking issues * #43244 * #70530 * #59618 Related hashbrown update: rust-lang/hashbrown#374
Don't drain-on-drop in DrainFilter impls of various collections. This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](rust-lang/rust#43244 (comment)) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](rust-lang/rfcs#3288). closes #101122 [ACP](rust-lang/libs-team#136) affected tracking issues * #43244 * #70530 * #59618 Related hashbrown update: rust-lang/hashbrown#374
Proposal
Problem statement
The current implementations can double-panic (via a panic-drop-panic cascade), may become aborts even on a single panic if the deny panic-in-drop RFC goes through and are not consistent with general Iterator laziness.
Motivation, use-cases
A panicking closure can lead to a double-panic while iterating. Playground link
Solution sketches
Add
#[must_use]
and remove drain-on-drop behavior from thedrain_filter
impls for these collections:Since it'll be redundant needed it will also remove
vec::DrainFilter::keep_rest()
Additionally
drain_filter
can be renamed toextract_filter
🚲🏚️ to avoid similarity toDrain
which will retain its drain-on-drop behavior since it's less problematic as it doesn't evaluate a closure for each item. To be bikeshed.Limitations
This may cause surprises with short-circuiting iterators. That can be worked around (unergonomically) by taking
by_ref
and then exhausting the rest once the main use is completed or by avoiding short-circuiting ops.Links and related work
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: