]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Refactor optional initializers
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 19 Nov 2024 16:24:59 +0000 (17:24 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:32:57 +0000 (12:32 +0100)
Refactor some optional initializer in the lowering stage to make them
more readable.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Change the
ternary expression with a more readable if.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/hir/rust-ast-lower-stmt.cc

index 5a825fd1139015d3416a858a209307699e0d79bc..8244e8ae2ba4e797f1858177d94fef9c8e58e025 100644 (file)
@@ -70,15 +70,17 @@ ASTLoweringStmt::visit (AST::LetStmt &stmt)
   HIR::Pattern *variables
     = ASTLoweringPattern::translate (stmt.get_pattern (), true);
 
-  auto type
-    = stmt.has_type () ? tl::optional<std::unique_ptr<Type>> (
-       std::unique_ptr<Type> (ASTLoweringType::translate (stmt.get_type ())))
-                      : tl::nullopt;
-  auto init_expression
-    = stmt.has_init_expr ()
-       ? tl::optional<std::unique_ptr<Expr>> (std::unique_ptr<HIR::Expr> (
-         ASTLoweringExpr::translate (stmt.get_init_expr ())))
-       : tl::nullopt;
+  tl::optional<std::unique_ptr<Type>> type = tl::nullopt;
+
+  if (stmt.has_type ())
+    type
+      = std::unique_ptr<Type> (ASTLoweringType::translate (stmt.get_type ()));
+
+  tl::optional<std::unique_ptr<HIR::Expr>> init_expression = tl::nullopt;
+
+  if (stmt.has_init_expr ())
+    init_expression = std::unique_ptr<HIR::Expr> (
+      ASTLoweringExpr::translate (stmt.get_init_expr ()));
 
   auto crate_num = mappings.get_current_crate ();
   Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),