• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Here we test all the places `|` is *syntactically* allowed.
2 // This is not a semantic test. We only test parsing.
3 
4 // check-pass
5 
main()6 fn main() {}
7 
8 // Test the `pat` macro fragment parser:
9 macro_rules! accept_pat {
10     ($p:pat) => {};
11 }
12 
13 accept_pat!((p | q));
14 accept_pat!((p | q,));
15 accept_pat!(TS(p | q));
16 accept_pat!(NS { f: p | q });
17 accept_pat!([p | q]);
18 
19 // Non-macro tests:
20 
21 #[cfg(FALSE)]
or_patterns()22 fn or_patterns() {
23     // Top level of `let`:
24     let (| A | B);
25     let (A | B);
26     let (A | B): u8;
27     let (A | B) = 0;
28     let (A | B): u8 = 0;
29 
30     // Top level of `for`:
31     for | A | B in 0 {}
32     for A | B in 0 {}
33 
34     // Top level of `while`:
35     while let | A | B = 0 {}
36     while let A | B = 0 {}
37 
38     // Top level of `if`:
39     if let | A | B = 0 {}
40     if let A | B = 0 {}
41 
42     // Top level of `match` arms:
43     match 0 {
44         | A | B => {}
45         A | B => {}
46     }
47 
48     // Functions:
49     fn fun((A | B): _) {}
50 
51     // Lambdas:
52     let _ = |(A | B): u8| ();
53 
54     // Parenthesis and tuple patterns:
55     let (A | B);
56     let (A | B,);
57 
58     // Tuple struct patterns:
59     let A(B | C);
60     let E::V(B | C);
61 
62     // Struct patterns:
63     let S { f1: B | C, f2 };
64     let E::V { f1: B | C, f2 };
65 
66     // Slice patterns:
67     let [A | B, .. | ..];
68 
69     // These bind as `(prefix p) | q` as opposed to `prefix (p | q)`:
70     let (box 0 | 1); // Unstable; we *can* change the precedence if we want.
71                      //~^ WARN box pattern syntax is experimental
72                      //~| WARN unstable syntax
73     let (&0 | 1);
74     let (&mut 0 | 1);
75     let (x @ 0 | 1);
76     let (ref x @ 0 | 1);
77     let (ref mut x @ 0 | 1);
78 }
79