Skip to content

Commit 7d2c911

Browse files
committed
Add libcore test
1 parent 9e7656c commit 7d2c911

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ where
375375
if A::MAY_HAVE_SIDE_EFFECT && sz_a > self.len {
376376
// FIXME(const_trait_impl): replace with `for`
377377
let mut i = 0;
378-
while i < sz_a - self.len {
378+
let upper_bound = sz_a - self.len;
379+
while i < upper_bound {
379380
// since next_back() may panic we increment the counters beforehand
380381
// to keep Zip's state in sync with the underlying iterator source
381382
self.a_len -= 1;
@@ -401,7 +402,7 @@ where
401402
if B::MAY_HAVE_SIDE_EFFECT && sz_b > self.len {
402403
// FIXME(const_trait_impl): replace with `for`
403404
let mut i = 0;
404-
while i < sz_a - self.len {
405+
while i < sz_b - self.len {
405406
self.b.next_back();
406407
i += 1;
407408
}

library/core/tests/iter/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,18 @@ pub fn extend_for_unit() {
100100
}
101101
assert_eq!(x, 5);
102102
}
103+
104+
#[test]
105+
fn test_const_iter() {
106+
const X: usize = {
107+
let mut n = 0;
108+
#[allow(for_loops_over_fallibles)]
109+
for a in Some(1) {
110+
n = a;
111+
}
112+
n
113+
};
114+
115+
const _: () = assert!(X == 1);
116+
assert_eq!(1, X);
117+
}

library/core/tests/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#![feature(const_cell_into_inner)]
1414
#![feature(const_convert)]
1515
#![feature(const_hash)]
16+
#![feature(const_for)]
1617
#![feature(const_heap)]
18+
#![feature(const_iter)]
1719
#![feature(const_maybe_uninit_as_mut_ptr)]
1820
#![feature(const_maybe_uninit_assume_init_read)]
1921
#![feature(const_nonnull_new)]

0 commit comments

Comments
 (0)