gcc/testsuite/rust/execute/torture/matches_macro.rs
raw| 1 | macro_rules! matches { |
| 2 | ($expression:expr, $($pattern:pat)|+ $( if $guard:expr ),*) => { |
| 3 | match $expression { |
| 4 | $($pattern)|+ => true, |
| 5 | _ => false, |
| 6 | } |
| 7 | } |
| 8 | } |
| 9 | |
| 10 | pub fn should_match() -> bool { |
| 11 | matches!(1, 1) |
| 12 | } |
| 13 | |
| 14 | pub fn shouldnt() -> bool { |
| 15 | matches!(1, 2) |
| 16 | } |
| 17 | |
| 18 | fn main() -> i32 { |
| 19 | let mut retval = 2; |
| 20 | |
| 21 | if should_match() { |
| 22 | retval -= 1; |
| 23 | } |
| 24 | |
| 25 | if !shouldnt() { |
| 26 | retval -= 1; |
| 27 | } |
| 28 | |
| 29 | retval |
| 30 | } |