Skip to content

Commit

Permalink
Add libcore test
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Nov 20, 2022
1 parent 9e7656c commit 7d2c911
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/core/src/iter/adapters/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ where
if A::MAY_HAVE_SIDE_EFFECT && sz_a > self.len {
// FIXME(const_trait_impl): replace with `for`
let mut i = 0;
while i < sz_a - self.len {
let upper_bound = sz_a - self.len;
while i < upper_bound {
// since next_back() may panic we increment the counters beforehand
// to keep Zip's state in sync with the underlying iterator source
self.a_len -= 1;
Expand All @@ -401,7 +402,7 @@ where
if B::MAY_HAVE_SIDE_EFFECT && sz_b > self.len {
// FIXME(const_trait_impl): replace with `for`
let mut i = 0;
while i < sz_a - self.len {
while i < sz_b - self.len {
self.b.next_back();
i += 1;
}
Expand Down
15 changes: 15 additions & 0 deletions library/core/tests/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,18 @@ pub fn extend_for_unit() {
}
assert_eq!(x, 5);
}

#[test]
fn test_const_iter() {
const X: usize = {
let mut n = 0;
#[allow(for_loops_over_fallibles)]
for a in Some(1) {
n = a;
}
n
};

const _: () = assert!(X == 1);
assert_eq!(1, X);
}
2 changes: 2 additions & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#![feature(const_cell_into_inner)]
#![feature(const_convert)]
#![feature(const_hash)]
#![feature(const_for)]
#![feature(const_heap)]
#![feature(const_iter)]
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_maybe_uninit_assume_init_read)]
#![feature(const_nonnull_new)]
Expand Down

0 comments on commit 7d2c911

Please sign in to comment.