]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix parsing of array expressions.
authorOwen Avery <powerboat9.gamer@gmail.com>
Mon, 27 Mar 2023 15:05:03 +0000 (11:05 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:28:39 +0000 (18:28 +0100)
Array expressions were being eagerly handled
outside of Pratt parsing.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser<ManagedTokenSource>::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 <powerboat9.gamer@gmail.com>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/array4.rs [new file with mode: 0644]
gcc/testsuite/rust/execute/torture/arrays.rs [new file with mode: 0644]

index 00766245825686795480dc0b2c14f3bc1816af4f..01d97d12d33e670399835188d2cd32757f7b6ca8 100644 (file)
@@ -7449,9 +7449,6 @@ Parser<ManagedTokenSource>::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 (file)
index 0000000..c70ca0a
--- /dev/null
@@ -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 (file)
index 0000000..e30285f
--- /dev/null
@@ -0,0 +1,3 @@
+fn main() -> i32 {
+    [55, 66, 77][1] - 66
+}