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 committed Jan 23, 2024
1 parent 1586de8 commit 5f7b258
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=lowering" }

Check failure on line 1 in gcc/testsuite/rust/compile/issue-2812.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-32bit

Test failure (FAIL)

(test for excess errors)

Check failure on line 1 in gcc/testsuite/rust/compile/issue-2812.rs

View workflow job for this annotation

GitHub Actions / build-and-check-ubuntu-64bit

Test failure (FAIL)

(test for excess errors)
fn foo_1(&self);
fn foo_1(&mut self);
fn foo_1(self);

0 comments on commit 5f7b258

Please sign in to comment.