summaryrefslogtreecommitdiffstats
path: root/tests/ui/or-patterns/bindings-runpass-2.rs
blob: 5b9bb748c7cee68594eb28e46dd270e0f73a7746 (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
// run-pass

fn or_at(x: Result<u32, u32>) -> u32 {
    match x {
        Ok(x @ 4) | Err(x @ (6 | 8)) => x,
        Ok(x @ 1 | x @ 2) => x,
        Err(x @ (0..=10 | 30..=40)) if x % 2 == 0 => x + 100,
        Err(x @ 0..=40) => x + 200,
        _ => 500,
    }
}

fn main() {
    assert_eq!(or_at(Ok(1)), 1);
    assert_eq!(or_at(Ok(2)), 2);
    assert_eq!(or_at(Ok(3)), 500);
    assert_eq!(or_at(Ok(4)), 4);
    assert_eq!(or_at(Ok(5)), 500);
    assert_eq!(or_at(Ok(6)), 500);
    assert_eq!(or_at(Err(1)), 201);
    assert_eq!(or_at(Err(2)), 102);
    assert_eq!(or_at(Err(3)), 203);
    assert_eq!(or_at(Err(4)), 104);
    assert_eq!(or_at(Err(5)), 205);
    assert_eq!(or_at(Err(6)), 6);
    assert_eq!(or_at(Err(7)), 207);
    assert_eq!(or_at(Err(8)), 8);
    assert_eq!(or_at(Err(20)), 220);
    assert_eq!(or_at(Err(50)), 500);
}