diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-29 16:37:16 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-01-31 14:16:49 +0100 |
commit | f7014b28b81f43f62086d75222a9cfe7ca562b27 (patch) | |
tree | ea09c9f4db63ab3bf0e71a5f620708cd7728da1f | |
parent | 938facc5e93a9ff31fe39ff00684e591c371fd37 (diff) | |
download | gcc-f7014b28b81f43f62086d75222a9cfe7ca562b27.zip gcc-f7014b28b81f43f62086d75222a9cfe7ca562b27.tar.gz gcc-f7014b28b81f43f62086d75222a9cfe7ca562b27.tar.bz2 |
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.
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 6 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/parse_range.rs | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index fe62864..72207a1 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 0000000..03469b1 --- /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[..]; +} |