From 0ddec9f44d6ce81eec7aa62c2d9b13c9094e7857 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Mon, 27 Mar 2023 11:05:03 -0400 Subject: Fix parsing of array expressions. Array expressions were being eagerly handled outside of Pratt parsing. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_expr_without_block): Remove direct array expression handling. gcc/testsuite/ChangeLog: * rust/compile/array4.rs: New test. * rust/execute/torture/arrays.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/parse/rust-parse-impl.h | 3 --- gcc/testsuite/rust/compile/array4.rs | 3 +++ gcc/testsuite/rust/execute/torture/arrays.rs | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/rust/compile/array4.rs create mode 100644 gcc/testsuite/rust/execute/torture/arrays.rs (limited to 'gcc') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 79dd4e2..7c554e8 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7449,9 +7449,6 @@ Parser::parse_expr_without_block ( case MOVE: // closure expr (though not all closure exprs require this) return parse_closure_expr (std::move (outer_attrs)); - case LEFT_SQUARE: - // array expr (creation, not index) - return parse_array_expr (std::move (outer_attrs)); default: { /* HACK: piggyback on pratt parsed expr and abuse polymorphism to * essentially downcast */ diff --git a/gcc/testsuite/rust/compile/array4.rs b/gcc/testsuite/rust/compile/array4.rs new file mode 100644 index 0000000..c70ca0a --- /dev/null +++ b/gcc/testsuite/rust/compile/array4.rs @@ -0,0 +1,3 @@ +pub fn foo() { + [0, 1, 2][1]; +} diff --git a/gcc/testsuite/rust/execute/torture/arrays.rs b/gcc/testsuite/rust/execute/torture/arrays.rs new file mode 100644 index 0000000..e30285f --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/arrays.rs @@ -0,0 +1,3 @@ +fn main() -> i32 { + [55, 66, 77][1] - 66 +} -- cgit v1.1