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] parser: Parse RangeFullExpr without erroring out
Date: Tue, 30 Aug 2022 13:42:52 +0000 (GMT)	[thread overview]
Message-ID: <20220830134252.B15533852776@sourceware.org> (raw)

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

commit b376c0cb37c9f712d60d8aad9aab37237adf3563
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Mon Aug 29 16:37:16 2022 +0200

    parser: Parse RangeFullExpr without erroring out

Diff:
---
 gcc/rust/parse/rust-parse-impl.h          | 6 +++++-
 gcc/testsuite/rust/compile/parse_range.rs | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index d925aca05e9..c4cfbe2cce9 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -14102,9 +14102,13 @@ std::unique_ptr<AST::RangeExpr>
 Parser<ManagedTokenSource>::parse_nud_range_exclusive_expr (
   const_TokenPtr tok, AST::AttrVec outer_attrs ATTRIBUTE_UNUSED)
 {
+  auto restrictions = ParseRestrictions ();
+  restrictions.expr_can_be_null = true;
+
   // FIXME: this probably parses expressions accidently or whatever
   // try parsing RHS (as tok has already been consumed in parse_expression)
-  std::unique_ptr<AST::Expr> right = parse_expr (LBP_DOT_DOT, AST::AttrVec ());
+  std::unique_ptr<AST::Expr> right
+    = parse_expr (LBP_DOT_DOT, AST::AttrVec (), restrictions);
 
   Location locus = tok->get_locus ();
 
diff --git a/gcc/testsuite/rust/compile/parse_range.rs b/gcc/testsuite/rust/compile/parse_range.rs
new file mode 100644
index 00000000000..03469b1f8d5
--- /dev/null
+++ b/gcc/testsuite/rust/compile/parse_range.rs
@@ -0,0 +1,9 @@
+// { dg-additional-options "-fsyntax-only" }
+
+fn main() {
+    let a = [1, 2, 3, 4];
+    let _ = a[0..];
+    let _ = a[..3];
+    let _ = a[0..3];
+    let _ = a[..];
+}

                 reply	other threads:[~2022-08-30 13:42 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=20220830134252.B15533852776@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).