summaryrefslogtreecommitdiffstats
path: root/src/test/ui/macros/macro-pat.rs
blob: baf816e53ea6208e309c855fc5aacc8b1fef8804 (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
63
64
65
// run-pass

macro_rules! mypat {
    () => (
        Some('y')
    )
}

macro_rules! char_x {
    () => (
        'x'
    )
}

macro_rules! some {
    ($x:pat) => (
        Some($x)
    )
}

macro_rules! indirect {
    () => (
        some!(char_x!())
    )
}

macro_rules! ident_pat {
    ($x:ident) => (
        $x
    )
}

fn f(c: Option<char>) -> usize {
    match c {
        Some('x') => 1,
        mypat!() => 2,
        _ => 3,
    }
}

pub fn main() {
    assert_eq!(1, f(Some('x')));
    assert_eq!(2, f(Some('y')));
    assert_eq!(3, f(None));

    assert_eq!(1, match Some('x') {
        Some(char_x!()) => 1,
        _ => 2,
    });

    assert_eq!(1, match Some('x') {
        some!(char_x!()) => 1,
        _ => 2,
    });

    assert_eq!(1, match Some('x') {
        indirect!() => 1,
        _ => 2,
    });

    assert_eq!(3, {
        let ident_pat!(x) = 2;
        x+1
    });
}