2019-08-18 16:53:08 -05:00
|
|
|
// Here we test all the places `|` is *syntactically* allowed.
|
|
|
|
// This is not a semantic test. We only test parsing.
|
|
|
|
|
|
|
|
// check-pass
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
// Test the `pat` macro fragment parser:
|
|
|
|
macro_rules! accept_pat {
|
2022-08-17 06:52:47 -05:00
|
|
|
($p:pat) => {};
|
2019-08-18 16:53:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
accept_pat!((p | q));
|
|
|
|
accept_pat!((p | q,));
|
|
|
|
accept_pat!(TS(p | q));
|
|
|
|
accept_pat!(NS { f: p | q });
|
|
|
|
accept_pat!([p | q]);
|
|
|
|
|
|
|
|
// Non-macro tests:
|
|
|
|
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
fn or_patterns() {
|
|
|
|
// Top level of `let`:
|
2022-11-21 04:23:53 -06:00
|
|
|
let (| A | B);
|
2021-02-12 18:04:37 -06:00
|
|
|
let (A | B);
|
|
|
|
let (A | B): u8;
|
|
|
|
let (A | B) = 0;
|
|
|
|
let (A | B): u8 = 0;
|
2019-08-18 16:53:08 -05:00
|
|
|
|
|
|
|
// Top level of `for`:
|
2022-11-21 04:23:53 -06:00
|
|
|
for | A | B in 0 {}
|
2019-08-18 16:53:08 -05:00
|
|
|
for A | B in 0 {}
|
|
|
|
|
|
|
|
// Top level of `while`:
|
2022-11-21 04:23:53 -06:00
|
|
|
while let | A | B = 0 {}
|
2019-08-18 16:53:08 -05:00
|
|
|
while let A | B = 0 {}
|
|
|
|
|
|
|
|
// Top level of `if`:
|
2022-11-21 04:23:53 -06:00
|
|
|
if let | A | B = 0 {}
|
2019-08-18 16:53:08 -05:00
|
|
|
if let A | B = 0 {}
|
|
|
|
|
|
|
|
// Top level of `match` arms:
|
|
|
|
match 0 {
|
2022-11-21 04:23:53 -06:00
|
|
|
| A | B => {}
|
2022-08-17 06:52:47 -05:00
|
|
|
A | B => {}
|
2019-08-18 16:53:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Functions:
|
|
|
|
fn fun((A | B): _) {}
|
|
|
|
|
|
|
|
// Lambdas:
|
|
|
|
let _ = |(A | B): u8| ();
|
|
|
|
|
|
|
|
// Parenthesis and tuple patterns:
|
|
|
|
let (A | B);
|
|
|
|
let (A | B,);
|
|
|
|
|
|
|
|
// Tuple struct patterns:
|
|
|
|
let A(B | C);
|
|
|
|
let E::V(B | C);
|
|
|
|
|
|
|
|
// Struct patterns:
|
|
|
|
let S { f1: B | C, f2 };
|
|
|
|
let E::V { f1: B | C, f2 };
|
|
|
|
|
|
|
|
// Slice patterns:
|
|
|
|
let [A | B, .. | ..];
|
|
|
|
|
|
|
|
// These bind as `(prefix p) | q` as opposed to `prefix (p | q)`:
|
2021-02-12 18:04:37 -06:00
|
|
|
let (box 0 | 1); // Unstable; we *can* change the precedence if we want.
|
2022-08-17 06:52:47 -05:00
|
|
|
//~^ WARN box pattern syntax is experimental
|
|
|
|
//~| WARN unstable syntax
|
2021-02-12 18:04:37 -06:00
|
|
|
let (&0 | 1);
|
|
|
|
let (&mut 0 | 1);
|
|
|
|
let (x @ 0 | 1);
|
|
|
|
let (ref x @ 0 | 1);
|
|
|
|
let (ref mut x @ 0 | 1);
|
2019-08-18 16:53:08 -05:00
|
|
|
}
|