Skip to content

Commit 8b9ac4d

Browse files
committed
Add test for underflow in specialized Zip's size_hint
1 parent 66a2606 commit 8b9ac4d

File tree

1 file changed

+20
-0
lines changed
  • library/core/tests/iter/adapters

1 file changed

+20
-0
lines changed

library/core/tests/iter/adapters/zip.rs

+20
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,23 @@ fn test_double_ended_zip() {
245245
assert_eq!(it.next_back(), Some((3, 3)));
246246
assert_eq!(it.next(), None);
247247
}
248+
249+
#[test]
250+
fn test_issue_82282() {
251+
fn overflowed_zip(arr: &[i32]) -> impl Iterator<Item = (i32, &())> {
252+
static UNIT_EMPTY_ARR: [(); 0] = [];
253+
254+
let mapped = arr.into_iter().map(|i| *i);
255+
let mut zipped = mapped.zip(UNIT_EMPTY_ARR.iter());
256+
zipped.next();
257+
zipped
258+
}
259+
260+
let arr = [1, 2, 3];
261+
let zip = overflowed_zip(&arr).zip(overflowed_zip(&arr));
262+
263+
assert_eq!(zip.size_hint(), (0, Some(0)));
264+
for _ in zip {
265+
panic!();
266+
}
267+
}

0 commit comments

Comments
 (0)