Skip to content

Commit 1f373f4

Browse files
Add test for panic in LL DrainFilter predicate
1 parent 0ae16b4 commit 1f373f4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/liballoc/tests/linked_list.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,41 @@ fn drain_filter_drop_panic_leak() {
565565
assert!(q.is_empty());
566566
}
567567

568+
#[test]
569+
fn drain_filter_pred_panic_leak() {
570+
static mut DROPS: i32 = 0;
571+
572+
#[derive(Debug)]
573+
struct D(u32);
574+
575+
impl Drop for D {
576+
fn drop(&mut self) {
577+
unsafe {
578+
DROPS += 1;
579+
}
580+
}
581+
}
582+
583+
let mut q = LinkedList::new();
584+
q.push_back(D(3));
585+
q.push_back(D(4));
586+
q.push_back(D(5));
587+
q.push_back(D(6));
588+
q.push_back(D(7));
589+
q.push_front(D(2));
590+
q.push_front(D(1));
591+
q.push_front(D(0));
592+
593+
catch_unwind(AssertUnwindSafe(|| drop(q.drain_filter(|item| if item.0 >= 2 {
594+
panic!()
595+
} else {
596+
true
597+
})))).ok();
598+
599+
assert_eq!(unsafe { DROPS }, 2); // 0 and 1
600+
assert_eq!(q.len(), 6);
601+
}
602+
568603
#[test]
569604
fn test_drop() {
570605
static mut DROPS: i32 = 0;

0 commit comments

Comments
 (0)