Skip to content

Commit

Permalink
Parse normal functions with self parameter correctly
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
braw-lee authored and CohenArthur committed Jan 26, 2024
1 parent 396565b commit bef4967
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gcc/rust/parse/rust-parse-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2946,8 +2946,8 @@ Parser<ManagedTokenSource>::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<std::unique_ptr<AST::Param>> function_params;
Expand Down
4 changes: 4 additions & 0 deletions gcc/testsuite/rust/compile/issue-2812.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// { dg-additional-options "-frust-compile-until=astvalidation" }
fn foo_1(&self);
fn foo_1(&mut self);
fn foo_1(self);

0 comments on commit bef4967

Please sign in to comment.