public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] fixed compiler error message on wildcard pattern within expression
Date: Mon, 30 Jan 2023 17:24:49 +0000 (GMT)	[thread overview]
Message-ID: <20230130172449.625643858D28@sourceware.org> (raw)

https://gcc.gnu.org/g:d17212591af78ba9894d1ca7aa457ec2340ca461

commit d17212591af78ba9894d1ca7aa457ec2340ca461
Author: Abdul Rafey <abdulrafeyq@gmail.com>
Date:   Sun Jan 29 17:05:23 2023 +0530

    fixed compiler error message on wildcard pattern within expression
    
    Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>

Diff:
---
 gcc/rust/parse/rust-parse-impl.h        | 6 ++++++
 gcc/testsuite/rust/compile/issue-867.rs | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index c19fe9b6ec4..17ca6bb49d7 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -13021,6 +13021,12 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
     case UNSAFE:
       return parse_unsafe_block_expr (std::move (outer_attrs),
 				      tok->get_locus ());
+    case UNDERSCORE:
+      add_error (
+	Error (tok->get_locus (),
+	       "use of %qs is not allowed on the right-side of an assignment",
+	       tok->get_token_description ()));
+      return nullptr;
     default:
       if (!restrictions.expr_can_be_null)
 	add_error (Error (tok->get_locus (),
diff --git a/gcc/testsuite/rust/compile/issue-867.rs b/gcc/testsuite/rust/compile/issue-867.rs
new file mode 100644
index 00000000000..8e120685c1a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-867.rs
@@ -0,0 +1,8 @@
+fn main() {
+    let _ = 42;
+    let a = _ + 123; // { dg-error "use of '_' is not allowed on the right-side of an assignment" }
+                     // { dg-error {failed to parse expression in let statement} "" { target *-*-* } .-1  }
+                     // { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .-2 }
+                     // { dg-error {unrecognised token '\}' for start of item} "" { target *-*-* } .+2 }
+                     // { dg-error {failed to parse item in crate} "" { target *-*-* } .+1 }
+}

                 reply	other threads:[~2023-01-30 17:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230130172449.625643858D28@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@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).