Skip to content

Commit

Permalink
gccrs: Add testcase for matches!() macro
Browse files Browse the repository at this point in the history
This adds a testcase for issue #2129.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/matches_macro.rs: New test.
  • Loading branch information
CohenArthur committed Feb 8, 2024
1 parent da5e5ee commit 1d8f5d5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions gcc/testsuite/rust/execute/torture/matches_macro.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1d8f5d5

Please sign in to comment.