* [COMMITTED] gccrs: parser: Parse RangeFullExpr without erroring out
@ 2023-01-31 13:24 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2023-01-31 13:24 UTC (permalink / raw)
To: gcc-patches; +Cc: gcc-rust, Arthur Cohen
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h: Allow parsing full range expressions without
erroring out.
gcc/testsuite/ChangeLog:
* rust/compile/parse_range.rs: New test.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/rust/parse/rust-parse-impl.h | 6 +++++-
gcc/testsuite/rust/compile/parse_range.rs | 9 +++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/parse_range.rs
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index fe628647653..72207a1bc22 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -14112,9 +14112,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[..];
+}
--
2.39.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-31 13:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 13:24 [COMMITTED] gccrs: parser: Parse RangeFullExpr without erroring out Arthur Cohen
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).