[committed,32/88] gccrs: parser: Fix parsing of closure param list

Message ID 20230405140411.3016563-33-arthur.cohen@embecosm.com
State Accepted
Headers
Series [committed,01/88] gccrs: fatal_error_flag: Fix typo in error message |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Arthur Cohen April 5, 2023, 2:03 p.m. UTC
  From: Arthur Cohen <arthur.cohen@embecosm.com>

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                | 2 ++
 gcc/testsuite/rust/compile/closure_move_expr.rs | 9 +++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/closure_move_expr.rs
  

Patch

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 3610790815c..4ceb978f7f4 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -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
index 00000000000..780c316e0af
--- /dev/null
+++ b/gcc/testsuite/rust/compile/closure_move_expr.rs
@@ -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
+}