diff mbox series

[COMMITTED,2/9] gccrs: Add testcase for matches!() macro

Message ID 20240221131636.3336103-5-arthur.cohen@embecosm.com
State New
Headers show
Series [COMMITTED,1/9] gccrs: Fix typo in RegionConstraints instance | expand

Commit Message

Arthur Cohen Feb. 21, 2024, 1:15 p.m. UTC
From: Arthur Cohen <arthur.cohen@embecosm.com>

This adds a testcase for issue #2129.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/matches_macro.rs: New test.
---
 .../rust/execute/torture/matches_macro.rs     | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 gcc/testsuite/rust/execute/torture/matches_macro.rs
diff mbox series

Patch

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 00000000000..7b61570727d
--- /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
+}