]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/iter.rs
Auto merge of #104915 - weihanglo:update-cargo, r=ehuss
[rust.git] / src / tools / miri / tests / pass / iter.rs
1 fn iter_empty_and_zst() {
2     // Iterate over a Unique::empty()
3     for _ in Vec::<u32>::new().iter() {
4         panic!("We should never be here.");
5     }
6
7     // Iterate over a ZST (uses arith_offset internally)
8     let mut count = 0;
9     for _ in &[(), (), ()] {
10         count += 1;
11     }
12     assert_eq!(count, 3);
13 }
14
15 fn test_iterator_step_by_nth() {
16     let mut it = (0..16).step_by(5);
17     assert_eq!(it.nth(0), Some(0));
18     assert_eq!(it.nth(0), Some(5));
19     assert_eq!(it.nth(0), Some(10));
20     assert_eq!(it.nth(0), Some(15));
21     assert_eq!(it.nth(0), None);
22 }
23
24 fn iter_any() {
25     let f = |x: &u8| 10u8 == *x;
26     f(&1u8);
27
28     let g = |(), x: &u8| 10u8 == *x;
29     g((), &1u8);
30
31     let h = |(), (), x: &u8| 10u8 == *x;
32     h((), (), &1u8);
33
34     [1, 2, 3u8].iter().any(|elt| 10 == *elt);
35 }
36
37 fn main() {
38     test_iterator_step_by_nth();
39     iter_any();
40     iter_empty_and_zst();
41 }