diff options
| author | bors <bors@rust-lang.org> | 2019-12-13 19:39:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-13 19:39:20 +0000 |
| commit | ff15e9670843f8bd6b54ab1b042d2095b4c0aa6d (patch) | |
| tree | ab93656235150d2f5d3104ec4d0de0004581a89b /src/liballoc | |
| parent | 703c82e5319c15929df38bb8611755b3eda5bd8e (diff) | |
| parent | d0cc289ec0fa35de2aa35df5445ebca332ccf4f6 (diff) | |
| download | rust-ff15e9670843f8bd6b54ab1b042d2095b4c0aa6d.tar.gz rust-ff15e9670843f8bd6b54ab1b042d2095b4c0aa6d.zip | |
Auto merge of #67284 - Centril:rollup-ghiukob, r=Centril
Rollup of 7 pull requests Successful merges: - #67026 (Improve diagnostics and code for exhaustiveness of empty matches) - #67235 (VecDeque: drop remaining items on destructor panic) - #67254 (dont ICE in case of invalid drop fn) - #67256 (Reduce allocs for validation errors) - #67274 (be explicit that mem::uninitialized is the same as MaybeUninit::uninit().assume_init()) - #67278 (`coerce_inner`: use initial `expected_ty`) - #67280 (docs: std::convert::From: Fix typo) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/collections/vec_deque.rs | 14 | ||||
| -rw-r--r-- | src/liballoc/tests/vec_deque.rs | 34 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index ebd3f010077..913613653a6 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -144,11 +144,23 @@ impl<T: Clone> Clone for VecDeque<T> { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<#[may_dangle] T> Drop for VecDeque<T> { fn drop(&mut self) { + /// Runs the destructor for all items in the slice when it gets dropped (normally or + /// during unwinding). + struct Dropper<'a, T>(&'a mut [T]); + + impl<'a, T> Drop for Dropper<'a, T> { + fn drop(&mut self) { + unsafe { + ptr::drop_in_place(self.0); + } + } + } + let (front, back) = self.as_mut_slices(); unsafe { + let _back_dropper = Dropper(back); // use drop for [T] ptr::drop_in_place(front); - ptr::drop_in_place(back); } // RawVec handles deallocation } diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index ebcc8320171..1ab3694a3ca 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -2,6 +2,7 @@ use std::collections::TryReserveError::*; use std::collections::{vec_deque::Drain, VecDeque}; use std::fmt::Debug; use std::mem::size_of; +use std::panic::catch_unwind; use std::{isize, usize}; use crate::hash; @@ -710,6 +711,39 @@ fn test_drop_clear() { } #[test] +fn test_drop_panic() { + static mut DROPS: i32 = 0; + + struct D(bool); + + impl Drop for D { + fn drop(&mut self) { + unsafe { + DROPS += 1; + } + + if self.0 { + panic!("panic in `drop`"); + } + } + } + + let mut q = VecDeque::new(); + q.push_back(D(false)); + q.push_back(D(false)); + q.push_back(D(false)); + q.push_back(D(false)); + q.push_back(D(false)); + q.push_front(D(false)); + q.push_front(D(false)); + q.push_front(D(true)); + + catch_unwind(move || drop(q)).ok(); + + assert_eq!(unsafe { DROPS }, 8); +} + +#[test] fn test_reserve_grow() { // test growth path A // [T o o H] -> [T o o H . . . . ] |
