From 7f5144d1c9638eee4499c45d6ee625ff670cbe69 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Thu, 2 Feb 2023 15:32:17 +0100 Subject: [PATCH] gccrs: parser: Fix parsing of closure param list 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 diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 3610790815c2..4ceb978f7f44 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7592,6 +7592,7 @@ Parser::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::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 000000000000..780c316e0af2 --- /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 +} -- 2.47.2