]> git.proxmox.com Git - rustc.git/blob - src/test/ui/macros/macro-pat.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / test / ui / macros / macro-pat.rs
1 // run-pass
2
3 macro_rules! mypat {
4 () => (
5 Some('y')
6 )
7 }
8
9 macro_rules! char_x {
10 () => (
11 'x'
12 )
13 }
14
15 macro_rules! some {
16 ($x:pat) => (
17 Some($x)
18 )
19 }
20
21 macro_rules! indirect {
22 () => (
23 some!(char_x!())
24 )
25 }
26
27 macro_rules! ident_pat {
28 ($x:ident) => (
29 $x
30 )
31 }
32
33 fn f(c: Option<char>) -> usize {
34 match c {
35 Some('x') => 1,
36 mypat!() => 2,
37 _ => 3,
38 }
39 }
40
41 pub fn main() {
42 assert_eq!(1, f(Some('x')));
43 assert_eq!(2, f(Some('y')));
44 assert_eq!(3, f(None));
45
46 assert_eq!(1, match Some('x') {
47 Some(char_x!()) => 1,
48 _ => 2,
49 });
50
51 assert_eq!(1, match Some('x') {
52 some!(char_x!()) => 1,
53 _ => 2,
54 });
55
56 assert_eq!(1, match Some('x') {
57 indirect!() => 1,
58 _ => 2,
59 });
60
61 assert_eq!(3, {
62 let ident_pat!(x) = 2;
63 x+1
64 });
65 }