From bef49670f6248e30ab888ecdbd52a8a1612e25ef Mon Sep 17 00:00:00 2001 From: Kushal Pal Date: Tue, 23 Jan 2024 17:23:05 +0530 Subject: [PATCH] Parse normal functions with `self` parameter correctly Fixes #2812 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function): Skip token if its a COMMA. gcc/testsuite/ChangeLog: * rust/compile/issue-2812.rs: New test. Signed-off-by: Kushal Pal --- gcc/rust/parse/rust-parse-impl.h | 4 ++-- gcc/testsuite/rust/compile/issue-2812.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-2812.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index d1cfa362f324..a43b38980361 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2946,8 +2946,8 @@ Parser::parse_function (AST::Visibility vis, && initial_param.error () != ParseSelfError::NOT_SELF) return nullptr; - if (initial_param.has_value ()) - skip_token (COMMA); + if (initial_param.has_value () && lexer.peek_token ()->get_id () == COMMA) + skip_token (); // parse function parameters (only if next token isn't right paren) std::vector> function_params; diff --git a/gcc/testsuite/rust/compile/issue-2812.rs b/gcc/testsuite/rust/compile/issue-2812.rs new file mode 100644 index 000000000000..173259b12914 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2812.rs @@ -0,0 +1,4 @@ +// { dg-additional-options "-frust-compile-until=astvalidation" } +fn foo_1(&self); +fn foo_1(&mut self); +fn foo_1(self);