]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: 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>
Thu, 6 Apr 2023 08:47:19 +0000 (10:47 +0200)
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 3610790815c25720d34f59a6a8fa4fa279652fe5..4ceb978f7f443fd4029f6926bdd764b7ec84741d 100644 (file)
@@ -7592,6 +7592,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)
        {
@@ -7608,6 +7609,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
+}