Skip to content

Commit ff33a66

Browse files
committed
regression test for leaks in the the Filter::next_chunk implementation
previously next_chunk would forget items rejected by the filter
1 parent f90972a commit ff33a66

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/tests/iter/adapters/filter.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::iter::*;
2+
use std::rc::Rc;
23

34
#[test]
45
fn test_iterator_filter_count() {
@@ -50,3 +51,15 @@ fn test_double_ended_filter() {
5051
assert_eq!(it.next().unwrap(), &2);
5152
assert_eq!(it.next_back(), None);
5253
}
54+
55+
#[test]
56+
fn test_next_chunk_does_not_leak() {
57+
let drop_witness: [_; 5] = std::array::from_fn(|_| Rc::new(()));
58+
59+
let v = (0..5).map(|i| drop_witness[i].clone()).collect::<Vec<_>>();
60+
let _ = v.into_iter().filter(|_| false).next_chunk::<1>();
61+
62+
for ref w in drop_witness {
63+
assert_eq!(Rc::strong_count(w), 1);
64+
}
65+
}

0 commit comments

Comments
 (0)