Use ptr::drop_in_place for VecDeque::truncate and VecDeque::clear#65933
Use ptr::drop_in_place for VecDeque::truncate and VecDeque::clear#65933bors merged 4 commits intorust-lang:masterfrom
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
Going to move this for to r? @alexcrichton as this is a libs team question. |
|
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
Ping from triage - this has sat idle for a week cc: @alexcrichton |
|
I don't think it needs any changes. |
|
I think it should be good to merge then, thanks! |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
|
@bors: r+ |
|
📌 Commit 27e0ab5 has been approved by |
Use ptr::drop_in_place for VecDeque::truncate and VecDeque::clear This commit allows `VecDeque::truncate` to take advantage of its (largely) contiguous memory layout and is consistent with the change in #64432 for `Vec`. As with the change to `Vec::truncate`, this changes both: - the drop order, from back-to-front to front-to-back - the behavior when dropping an element panics For consistency, it also changes the behavior when dropping an element panics for `VecDeque::clear`. These changes in behavior can be observed. This example ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d0b1f2edc123437a2f704cbe8d93d828)) ```rust use std::collections::VecDeque; fn main() { struct Bomb(usize); impl Drop for Bomb { fn drop(&mut self) { panic!(format!("{}", self.0)); } } let mut v = VecDeque::from(vec![Bomb(0), Bomb(1)]); std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { v.truncate(0); })); std::mem::forget(v); } ``` panics printing `1` today and succeeds. `v.clear()` panics printing `0` today and succeeds. With the change, `v.clear()`, `v.truncate(0)`, and dropping the `VecDeque` all panic printing `0` first and then abort with a double-panic printing `1`. The motivation for this was making `VecDeque::truncate` more efficient since it was used in the implementation of `VecDeque::clone_from` (#65069), but it also makes behavior more consistent within the `VecDeque` and with `Vec` if that change is accepted (this probably doesn't make sense to merge if not). This might need a crater run and an FCP as well.
|
☀️ Test successful - checks-azure |
This commit allows
VecDeque::truncateto take advantage of its (largely) contiguous memory layout and is consistent with the change in #64432 forVec. As with the change toVec::truncate, this changes both:For consistency, it also changes the behavior when dropping an element panics for
VecDeque::clear.These changes in behavior can be observed. This example (playground)
panics printing
1today and succeeds.v.clear()panics printing0today and succeeds. With the change,v.clear(),v.truncate(0), and dropping theVecDequeall panic printing0first and then abort with a double-panic printing1.The motivation for this was making
VecDeque::truncatemore efficient since it was used in the implementation ofVecDeque::clone_from(#65069), but it also makes behavior more consistent within theVecDequeand withVecif that change is accepted (this probably doesn't make sense to merge if not).This might need a crater run and an FCP as well.