rust/src/liballoc
bors bc0e288ad0 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.
2019-11-11 19:20:54 +00:00
..
alloc liballoc: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
benches bump rand to fix Miri failures 2019-08-04 14:50:26 +02:00
collections Auto merge of #65933 - crgl:vec-deque-truncate, r=alexcrichton 2019-11-11 19:20:54 +00:00
prelude Replace SliceConcatExt trait with inherent methods and SliceConcat helper trait 2019-07-05 11:49:30 +02:00
raw_vec A few cosmetic improvements to code & comments in liballoc and libcore 2019-09-06 16:02:25 +01:00
rc Add implementations for converting boxed slices into boxed arrays 2019-08-05 10:26:53 -04:00
sync Add implementations for converting boxed slices into boxed arrays 2019-08-05 10:26:53 -04:00
tests Auto merge of #65091 - sekineh:into-iter-sorted, r=KodrAus 2019-10-31 15:15:53 +00:00
alloc.rs Snap cfgs to new beta 2019-09-25 08:42:46 -04:00
borrow.rs Add Cow::is_borrowed and Cow::is_owned 2019-10-22 19:56:41 -04:00
boxed.rs Uninitialized boxes: check for zero-size allocation based on Layout::size 2019-10-16 20:32:58 +02:00
Cargo.toml bump rand to fix Miri failures 2019-08-04 14:50:26 +02:00
fmt.rs example for padding any format 2019-10-17 23:02:09 +02:00
lib.rs gate rustc_on_unimplemented under rustc_attrs 2019-11-06 07:34:51 +01:00
macros.rs Improve hygiene of alloc::format! 2019-09-07 22:40:57 +03:00
raw_vec.rs Const-stabilize Vec::new. 2019-09-16 16:45:16 +02:00
rc.rs Reverted PhantomData in LinkedList, fixed PhantomData markers in Rc and Arc 2019-11-05 23:36:54 +03:00
slice.rs Stabilize slice::repeat (feature repeat_generic_slice) 2019-10-02 04:48:15 +00:00
str.rs Apply clippy::needless_return suggestions 2019-10-22 19:23:10 +02:00
string.rs Rollup merge of #66111 - RalfJung:from_raw_parts, r=Centril 2019-11-07 09:20:41 +09:00
sync.rs Reverted PhantomData in LinkedList, fixed PhantomData markers in Rc and Arc 2019-11-05 23:36:54 +03:00
tests.rs Add implementations for converting boxed slices into boxed arrays 2019-08-05 10:26:53 -04:00
vec.rs Rollup merge of #65887 - lzutao:doc-vec-get, r=rkruppe 2019-10-28 21:36:06 +01:00