diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-13 20:35:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-13 20:35:30 +0100 |
| commit | 48164f8a17501e7386afa4a371432168e598fcb5 (patch) | |
| tree | 364a32874b20b34dc04227e02488bedc7555e247 /src/liballoc/tests | |
| parent | df9e491fb238ff7b7bfee8dd2d3f01158ac8b0d3 (diff) | |
| parent | 82c09b75d7fef78db2d485793cfa8bf5583ff7cf (diff) | |
| download | rust-48164f8a17501e7386afa4a371432168e598fcb5.tar.gz rust-48164f8a17501e7386afa4a371432168e598fcb5.zip | |
Rollup merge of #67235 - jonas-schievink:vecdeque-leak, r=KodrAus
VecDeque: drop remaining items on destructor panic Closes https://github.com/rust-lang/rust/issues/67232
Diffstat (limited to 'src/liballoc/tests')
| -rw-r--r-- | src/liballoc/tests/vec_deque.rs | 34 |
1 files changed, 34 insertions, 0 deletions
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 . . . . ] |
