]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add testcase for matches!() macro
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 6 Feb 2024 16:01:46 +0000 (17:01 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 21 Feb 2024 12:51:25 +0000 (13:51 +0100)
This adds a testcase for issue #2129.

gcc/testsuite/ChangeLog:

* rust/execute/torture/matches_macro.rs: New test.

gcc/testsuite/rust/execute/torture/matches_macro.rs [new file with mode: 0644]

diff --git a/gcc/testsuite/rust/execute/torture/matches_macro.rs b/gcc/testsuite/rust/execute/torture/matches_macro.rs
new file mode 100644 (file)
index 0000000..7b61570
--- /dev/null
@@ -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
+}