From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id E71A7385781A; Tue, 31 Jan 2023 13:14:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E71A7385781A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675170886; bh=Vj91ahVNMyVe13H9/ZpWtrKSqGmho661zN2EX3GW41k=; h=From:To:Subject:Date:From; b=uz88psclmLy0HDfooz3mpgQUce45rI21YuHvGQH/4FMEDcxhnYxjMUPg8atEOOyNh EoneHHSLZIBRy8FA0mmZiuXp+DIilzr5+WnEMsMiMD+WMiUIwANIMznr80wF62JSV+ datqn6tHjaYHwI3Ied9ecyoJdMvqmNwNlOvJzh7Y= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5540] gccrs: parser: Parse RangeFullExpr without erroring out X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/master X-Git-Oldrev: 938facc5e93a9ff31fe39ff00684e591c371fd37 X-Git-Newrev: f7014b28b81f43f62086d75222a9cfe7ca562b27 Message-Id: <20230131131446.E71A7385781A@sourceware.org> Date: Tue, 31 Jan 2023 13:14:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f7014b28b81f43f62086d75222a9cfe7ca562b27 commit r13-5540-gf7014b28b81f43f62086d75222a9cfe7ca562b27 Author: Arthur Cohen Date: Mon Aug 29 16:37:16 2022 +0200 gccrs: parser: Parse RangeFullExpr without erroring out 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. 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 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 Parser::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 right = parse_expr (LBP_DOT_DOT, AST::AttrVec ()); + std::unique_ptr 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[..]; +}