https://gcc.gnu.org/g:3745ccf7fb73b1df02177a0ed2392c58849e35e5

commit r16-6844-g3745ccf7fb73b1df02177a0ed2392c58849e35e5
Author: lenny.chiadmi-delage <[email protected]>
Date:   Tue Jan 6 14:51:14 2026 +0000

    gccrs: handle outer attributes in expression parsing
    
    Fix parsing of outer attributes in expressions.
    
    Fixes Rust-GCC/gccrs#3904
    
    gcc/rust/ChangeLog:
    
            * parse/rust-parse-impl-expr.hxx(Parser::null_denotation): Add
            HASH case to handle outer attributes in expressions.
    
    Signed-off-by: lenny.chiadmi-delage <[email protected]>

Diff:
---
 gcc/rust/parse/rust-parse-impl-expr.hxx | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/gcc/rust/parse/rust-parse-impl-expr.hxx 
b/gcc/rust/parse/rust-parse-impl-expr.hxx
index 96a2686df00f..b870273e27c8 100644
--- a/gcc/rust/parse/rust-parse-impl-expr.hxx
+++ b/gcc/rust/parse/rust-parse-impl-expr.hxx
@@ -1901,6 +1901,32 @@ Parser<ManagedTokenSource>::null_denotation 
(AST::AttrVec outer_attrs,
        return null_denotation_path (std::move (path), std::move (outer_attrs),
                                     restrictions);
       }
+    case HASH:
+      {
+       // Parse outer attributes and then the expression that follows
+       AST::AttrVec attrs = parse_outer_attributes ();
+
+       // Merge with any existing outer attributes
+       if (!outer_attrs.empty ())
+         attrs.insert (attrs.begin (), outer_attrs.begin (),
+                       outer_attrs.end ());
+
+       // Try to parse the expression that should follow the attributes
+       auto expr = parse_expr (std::move (attrs), restrictions);
+       if (!expr)
+         {
+           /* If parsing failed and we're at a semicolon, provide a better
+            * error
+            */
+           const_TokenPtr next_tok = lexer.peek_token ();
+           if (next_tok->get_id () == SEMICOLON)
+             add_error (Error (next_tok->get_locus (),
+                               "expected expression, found %<;%>"));
+           return tl::unexpected<Parse::Error::Expr> (
+             Parse::Error::Expr::CHILD_ERROR);
+         }
+       return expr;
+      }
     default:
       if (tok->get_id () == LEFT_SHIFT)
        {

Reply via email to