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.
This commit is contained in:
Arthur Cohen
2022-08-29 16:37:16 +02:00
parent 938facc5e9
commit f7014b28b8
2 changed files with 14 additions and 1 deletions

View File

@@ -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 ();

View File

@@ -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[..];
}