aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-02-06 17:01:46 +0100
committerCohenArthur <arthur.cohen@embecosm.com>2024-02-08 10:23:23 +0000
commit1d8f5d5853f553e465b5a591541ede344500c9a4 (patch)
tree85131fe50cb5aedae2d78cff5bb02f86f8132477 /gcc
parentda5e5ee4677c4735104805d69c5f66d07d9cd23a (diff)
downloadgcc-1d8f5d5853f553e465b5a591541ede344500c9a4.zip
gcc-1d8f5d5853f553e465b5a591541ede344500c9a4.tar.gz
gcc-1d8f5d5853f553e465b5a591541ede344500c9a4.tar.bz2
gccrs: Add testcase for matches!() macro
This adds a testcase for issue #2129. gcc/testsuite/ChangeLog: * rust/execute/torture/matches_macro.rs: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/rust/execute/torture/matches_macro.rs30
1 files changed, 30 insertions, 0 deletions
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 0000000..7b61570
--- /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
+}