Skip to content

Commit

Permalink
Add test for underflow in specialized Zip's size_hint
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFire13 committed Mar 3, 2021
1 parent 66a2606 commit 8b9ac4d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/core/tests/iter/adapters/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,23 @@ fn test_double_ended_zip() {
assert_eq!(it.next_back(), Some((3, 3)));
assert_eq!(it.next(), None);
}

#[test]
fn test_issue_82282() {
fn overflowed_zip(arr: &[i32]) -> impl Iterator<Item = (i32, &())> {
static UNIT_EMPTY_ARR: [(); 0] = [];

let mapped = arr.into_iter().map(|i| *i);
let mut zipped = mapped.zip(UNIT_EMPTY_ARR.iter());
zipped.next();
zipped
}

let arr = [1, 2, 3];
let zip = overflowed_zip(&arr).zip(overflowed_zip(&arr));

assert_eq!(zip.size_hint(), (0, Some(0)));
for _ in zip {
panic!();
}
}

0 comments on commit 8b9ac4d

Please sign in to comment.