about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/iter.rs
blob: 31d0d7442d9d2f3c144e6e6a2c9a67928f0302d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn iter_empty_and_zst() {
    // Iterate over a Unique::empty()
    for _ in Vec::<u32>::new().iter() {
        panic!("We should never be here.");
    }

    // Iterate over a ZST (uses arith_offset internally)
    let mut count = 0;
    for _ in &[(), (), ()] {
        count += 1;
    }
    assert_eq!(count, 3);
}

fn test_iterator_step_by_nth() {
    let mut it = (0..16).step_by(5);
    assert_eq!(it.nth(0), Some(0));
    assert_eq!(it.nth(0), Some(5));
    assert_eq!(it.nth(0), Some(10));
    assert_eq!(it.nth(0), Some(15));
    assert_eq!(it.nth(0), None);
}

fn iter_any() {
    let f = |x: &u8| 10u8 == *x;
    f(&1u8);

    let g = |(), x: &u8| 10u8 == *x;
    g((), &1u8);

    let h = |(), (), x: &u8| 10u8 == *x;
    h((), (), &1u8);

    [1, 2, 3u8].iter().any(|elt| 10 == *elt);
}

fn main() {
    test_iterator_step_by_nth();
    iter_any();
    iter_empty_and_zst();
}