]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
parser: Fix parsing of closure param list
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 2 Feb 2023 14:32:17 +0000 (15:32 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 3 Feb 2023 10:50:00 +0000 (11:50 +0100)
gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_closure_expr): Advance tokens
properly when parsing closure param list.

gcc/testsuite/ChangeLog:

* rust/compile/closure_move_expr.rs: New test.

gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/closure_move_expr.rs [new file with mode: 0644]

index f60d34fdb94df978c2923cfaa0277f908a2b7d5a..a3fc9f34cdb524c0bac995a61084a8b12a08a568 100644 (file)
@@ -7590,6 +7590,7 @@ Parser<ManagedTokenSource>::parse_closure_expr (AST::AttrVec outer_attrs)
     case PIPE:
       // actually may have parameters
       lexer.skip_token ();
+      t = lexer.peek_token ();
 
       while (t->get_id () != PIPE)
        {
@@ -7606,6 +7607,7 @@ Parser<ManagedTokenSource>::parse_closure_expr (AST::AttrVec outer_attrs)
 
          if (lexer.peek_token ()->get_id () != COMMA)
            {
+             lexer.skip_token ();
              // not an error but means param list is done
              break;
            }
diff --git a/gcc/testsuite/rust/compile/closure_move_expr.rs b/gcc/testsuite/rust/compile/closure_move_expr.rs
new file mode 100644 (file)
index 0000000..780c316
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-additional-options "-fsyntax-only" }
+
+fn foo() {
+    move |l: u32, r: u32| l + r
+}
+
+fn foo2() {
+    |l: u32, r: u32| l + r
+}