From: Arthur Cohen Date: Mon, 29 Aug 2022 14:37:16 +0000 (+0200) Subject: gccrs: parser: Parse RangeFullExpr without erroring out X-Git-Tag: basepoints/gcc-14~1667 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7014b28b81f43f62086d75222a9cfe7ca562b27;p=thirdparty%2Fgcc.git 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 --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index fe628647653f..72207a1bc226 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 000000000000..03469b1f8d52 --- /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[..]; +}