mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #82289 - SkiFire13:fix-issue-82282, r=m-ou-se
Fix underflow in specialized ZipImpl::size_hint Fixes #82282
This commit is contained in:
commit
ee796c6523
@ -200,6 +200,7 @@ where
|
||||
} else if A::MAY_HAVE_SIDE_EFFECT && self.index < self.a.size() {
|
||||
let i = self.index;
|
||||
self.index += 1;
|
||||
self.len += 1;
|
||||
// match the base implementation's potential side effects
|
||||
// SAFETY: we just checked that `i` < `self.a.len()`
|
||||
unsafe {
|
||||
@ -258,7 +259,7 @@ where
|
||||
if sz_a != sz_b {
|
||||
let sz_a = self.a.size();
|
||||
if A::MAY_HAVE_SIDE_EFFECT && sz_a > self.len {
|
||||
for _ in 0..sz_a - cmp::max(self.len, self.index) {
|
||||
for _ in 0..sz_a - self.len {
|
||||
self.a.next_back();
|
||||
}
|
||||
}
|
||||
|
@ -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!();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user