gccrs: Add testcase for matches!() macro
This adds a testcase for issue #2129. gcc/testsuite/ChangeLog: * rust/execute/torture/matches_macro.rs: New test.
This commit is contained in:
parent
8534cc772d
commit
4cabeacc38
1 changed files with 30 additions and 0 deletions
30
gcc/testsuite/rust/execute/torture/matches_macro.rs
Normal file
30
gcc/testsuite/rust/execute/torture/matches_macro.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
macro_rules! matches {
|
||||
($expression:expr, $($pattern:pat)|+ $( if $guard:expr ),*) => {
|
||||
match $expression {
|
||||
$($pattern)|+ => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn should_match() -> bool {
|
||||
matches!(1, 1)
|
||||
}
|
||||
|
||||
pub fn shouldnt() -> bool {
|
||||
matches!(1, 2)
|
||||
}
|
||||
|
||||
fn main() -> i32 {
|
||||
let mut retval = 2;
|
||||
|
||||
if should_match() {
|
||||
retval -= 1;
|
||||
}
|
||||
|
||||
if !shouldnt() {
|
||||
retval -= 1;
|
||||
}
|
||||
|
||||
retval
|
||||
}
|
Loading…
Add table
Reference in a new issue