Skip to content

Commit

Permalink
regression test for leaks in the the Filter::next_chunk implementation
Browse files Browse the repository at this point in the history
previously next_chunk would forget items rejected by the filter
  • Loading branch information
the8472 committed Jun 25, 2024
1 parent 2be2d77 commit 0d7aef9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions library/core/tests/iter/adapters/filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::iter::*;
use std::rc::Rc;

#[test]
fn test_iterator_filter_count() {
Expand Down Expand Up @@ -50,3 +51,15 @@ fn test_double_ended_filter() {
assert_eq!(it.next().unwrap(), &2);
assert_eq!(it.next_back(), None);
}

#[test]
fn test_next_chunk_does_not_leak() {
let drop_witness: [_; 5] = std::array::from_fn(|_| Rc::new(()));

let v = (0..5).map(|i| drop_witness[i].clone()).collect::<Vec<_>>();
let _ = v.into_iter().filter(|_| false).next_chunk::<1>();

for ref w in drop_witness {
assert_eq!(Rc::strong_count(w), 1);
}
}

0 comments on commit 0d7aef9

Please sign in to comment.