From: arthur.cohen@embecosm.com
To: gcc-patches@gcc.gnu.org
Cc: gcc-rust@gcc.gnu.org, Arthur Cohen <arthur.cohen@embecosm.com>
Subject: [COMMITTED 2/9] gccrs: Add testcase for matches!() macro
Date: Wed, 21 Feb 2024 14:15:20 +0100 [thread overview]
Message-ID: <20240221131636.3336103-5-arthur.cohen@embecosm.com> (raw)
In-Reply-To: <20240221131636.3336103-2-arthur.cohen@embecosm.com>
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 --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
+}
--
2.42.1
next prev parent reply other threads:[~2024-02-21 13:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 13:15 [PATCHSET] Update Rust frontend 21/02/2024 arthur.cohen
2024-02-21 13:15 ` [COMMITTED 1/9] gccrs: Fix typo in RegionConstraints instance arthur.cohen
2024-02-21 13:15 ` arthur.cohen [this message]
2024-02-21 13:15 ` [COMMITTED 3/9] gccrs: Fix rebinding imports arthur.cohen
2024-02-21 13:15 ` [COMMITTED 4/9] gccrs: expand: Fix formatting for "macro not found" error arthur.cohen
2024-02-21 13:15 ` [COMMITTED 5/9] gccrs: Add testcase for #[rustc_const_stable] arthur.cohen
2024-02-21 13:15 ` [COMMITTED 6/9] gccrs: add powi intrinsics arthur.cohen
2024-02-21 13:15 ` [COMMITTED 7/9] gccrs: Fix lookup of TuplePattern sub-pattern types arthur.cohen
2024-02-21 13:15 ` [COMMITTED 8/9] gccrs: Add variadic check on function params arthur.cohen
2024-02-21 13:15 ` [COMMITTED 9/9] Update copyright years arthur.cohen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240221131636.3336103-5-arthur.cohen@embecosm.com \
--to=arthur.cohen@embecosm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gcc-rust@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).