[gcc r14-8039] gccrs: Fix pub unit type parsing

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:13:19 GMT 2024


https://gcc.gnu.org/g:f209a01840a365365100c0ff4a31c0bab2ed2693

commit r14-8039-gf209a01840a365365100c0ff4a31c0bab2ed2693
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Mon Oct 16 11:28:34 2023 +0200

    gccrs: Fix pub unit type parsing
    
    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>

Diff:
---
 gcc/rust/parse/rust-parse-impl.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 07f95a61ec2..345ef0eeb6e 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -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


More information about the Gcc-cvs mailing list