]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix pub unit type parsing
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 16 Oct 2023 09:28:34 +0000 (11:28 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:09:12 +0000 (19:09 +0100)
Public unit types where not parsed correctly due to visibility specifiers
within parenthesis. Fixes #2648.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_visibility): Relax constraints
over public visibility return condition in order to accept pub unit
types.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/parse/rust-parse-impl.h

index 07f95a61ec294291a587e2fb8aa1dcb4faed2548..345ef0eeb6ee9ddd789e1a0a32af2664a03f7afc 100644 (file)
@@ -2296,8 +2296,11 @@ Parser<ManagedTokenSource>::parse_visibility ()
   auto vis_loc = lexer.peek_token ()->get_locus ();
   lexer.skip_token ();
 
-  // create simple pub visibility if no parentheses
-  if (lexer.peek_token ()->get_id () != LEFT_PAREN)
+  // create simple pub visibility if
+  // - found no parentheses
+  // - found unit type `()`
+  if (lexer.peek_token ()->get_id () != LEFT_PAREN
+      || lexer.peek_token (1)->get_id () == RIGHT_PAREN)
     {
       return AST::Visibility::create_public (vis_loc);
       // or whatever