Skip to content

Commit 503b8fa

Browse files
committed
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 <kushalpal109@gmail.com>
1 parent 1586de8 commit 503b8fa

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

gcc/rust/parse/rust-parse-impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2946,8 +2946,8 @@ Parser<ManagedTokenSource>::parse_function (AST::Visibility vis,
29462946
&& initial_param.error () != ParseSelfError::NOT_SELF)
29472947
return nullptr;
29482948

2949-
if (initial_param.has_value ())
2950-
skip_token (COMMA);
2949+
if (initial_param.has_value () && lexer.peek_token ()->get_id () == COMMA)
2950+
skip_token ();
29512951

29522952
// parse function parameters (only if next token isn't right paren)
29532953
std::vector<std::unique_ptr<AST::Param>> function_params;
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// { dg-additional-options "-frust-compile-until=astvalidation" }
2+
fn foo_1(&self);
3+
fn foo_1(&mut self);
4+
fn foo_1(self);

0 commit comments

Comments
 (0)