]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Parse normal functions with `self` parameter correctly
authorKushal Pal <kushalpal109@gmail.com>
Tue, 23 Jan 2024 11:53:05 +0000 (17:23 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 7 Feb 2024 11:40:21 +0000 (12:40 +0100)
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>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/issue-2812.rs [new file with mode: 0644]

index c622ed7bc97190c98396a944eddb1db48a4d6874..89e3731a8984a5a62af342b62d52f3fa690c1ebc 100644 (file)
@@ -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;
diff --git a/gcc/testsuite/rust/compile/issue-2812.rs b/gcc/testsuite/rust/compile/issue-2812.rs
new file mode 100644 (file)
index 0000000..173259b
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-additional-options "-frust-compile-until=astvalidation" }
+fn foo_1(&self);
+fn foo_1(&mut self);
+fn foo_1(self);