aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-02-06 17:01:46 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-02-21 13:51:25 +0100
commit4cabeacc388b4ec8dfa41bf9c99b0dbd87d4b1f4 (patch)
tree57c455c3770384dfe0797dd765b71cc80572d2a2
parent8534cc772def8142379c0e72ab6392d40f3f60f6 (diff)
downloadgcc-4cabeacc388b4ec8dfa41bf9c99b0dbd87d4b1f4.zip
gcc-4cabeacc388b4ec8dfa41bf9c99b0dbd87d4b1f4.tar.gz
gcc-4cabeacc388b4ec8dfa41bf9c99b0dbd87d4b1f4.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.
-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
+}