about summary refs log tree commit diff
path: root/tests/ui/match/postfix-match/postfix-match.rs
blob: 03c4e8ab5451f38e54b81127756fd9f9f285248f (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//@ run-pass

#![feature(postfix_match)]

struct Bar {
    foo: u8,
    baz: u8,
}

pub fn main() {
    let thing = Some("thing");

    thing.match {
        Some("nothing") => {},
        Some(text) if text.eq_ignore_ascii_case("tapir")  => {},
        Some("true") | Some("false") => {},
        Some("thing") => {},
        Some(_) => {},
        None => {}
    };

    let num = 2u8;

    num.match {
        0 => {},
        1..=5 => {},
        _ => {},
    };

    let slic = &[1, 2, 3, 4][..];

    slic.match {
        [1] => {},
        [2, _tail @ ..] => {},
        [1, _] => {},
        _ => {},
    };

    slic[0].match {
        1 => 0,
        i => i,
    };

    let out = (1, 2).match {
        (1, 3) => 0,
        (_, 1) => 0,
        (1, i) => i,
        _ => 3,
    };
    assert!(out == 2);

    let strct = Bar {
        foo: 3,
        baz: 4
    };

    strct.match {
        Bar { foo: 1, .. } => {},
        Bar { baz: 2, .. } => {},
        _ => (),
    };
}