https://gcc.gnu.org/g:1d8f5d5853f553e465b5a591541ede344500c9a4
commit 1d8f5d5853f553e465b5a591541ede344500c9a4 Author: Arthur Cohen <arthur.co...@embecosm.com> Date: Tue Feb 6 17:01:46 2024 +0100 gccrs: Add testcase for matches!() macro This adds a testcase for issue #2129. gcc/testsuite/ChangeLog: * rust/execute/torture/matches_macro.rs: New test. Diff: --- .../rust/execute/torture/matches_macro.rs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gcc/testsuite/rust/execute/torture/matches_macro.rs b/gcc/testsuite/rust/execute/torture/matches_macro.rs new file mode 100644 index 000000000000..7b61570727d8 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/matches_macro.rs @@ -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 +}