diff options
| author | bors <bors@rust-lang.org> | 2019-11-11 19:20:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-11 19:20:54 +0000 |
| commit | bc0e288ad02ef362b5a6c42aaf61f2901c9b46db (patch) | |
| tree | 517fef0f33192847e5c3d5826e691c4a0247648f /src/test/rustdoc-js-std/macro-check.js | |
| parent | 56237d75b4271a8a2e0f47d86ea76ebf6d966152 (diff) | |
| parent | 27e0ab578cc0fc4c72da54bbeb42c0c44d848207 (diff) | |
| download | rust-bc0e288ad02ef362b5a6c42aaf61f2901c9b46db.tar.gz rust-bc0e288ad02ef362b5a6c42aaf61f2901c9b46db.zip | |
Auto merge of #65933 - crgl:vec-deque-truncate, r=alexcrichton
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.
Diffstat (limited to 'src/test/rustdoc-js-std/macro-check.js')
0 files changed, 0 insertions, 0 deletions
