]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: parser: Parse let-else statements
authorArthur Cohen <arthur.cohen@embecosm.com>
Wed, 5 Mar 2025 15:30:04 +0000 (15:30 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 31 Mar 2025 19:07:15 +0000 (21:07 +0200)
gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_let_stmt): Add new parsing in case of `else` token.

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

index dd6086896f8386d60a3bdacdd0bff347a546ce6c..71d72504cfc3384a7e7c5944d58019446649e886 100644 (file)
@@ -6163,6 +6163,10 @@ Parser<ManagedTokenSource>::parse_let_stmt (AST::AttrVec outer_attrs,
        }
     }
 
+  tl::optional<std::unique_ptr<AST::Expr>> else_expr = tl::nullopt;
+  if (maybe_skip_token (ELSE))
+    else_expr = parse_block_expr ();
+
   if (restrictions.consume_semi)
     {
       // `stmt` macro variables are parsed without a semicolon, but should be
@@ -6177,7 +6181,7 @@ Parser<ManagedTokenSource>::parse_let_stmt (AST::AttrVec outer_attrs,
 
   return std::unique_ptr<AST::LetStmt> (
     new AST::LetStmt (std::move (pattern), std::move (expr), std::move (type),
-                     std::move (outer_attrs), locus));
+                     std::move (else_expr), std::move (outer_attrs), locus));
 }
 
 // Parses a type path.