From: Pierre-Emmanuel Patry Date: Tue, 19 Nov 2024 16:24:59 +0000 (+0100) Subject: gccrs: Refactor optional initializers X-Git-Tag: basepoints/gcc-16~1021 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=45d4f73b81dcd26df03e5e210a1f50803d1d4733;p=thirdparty%2Fgcc.git gccrs: Refactor optional initializers 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 --- diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc index 5a825fd1139..8244e8ae2ba 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.cc +++ b/gcc/rust/hir/rust-ast-lower-stmt.cc @@ -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 (ASTLoweringType::translate (stmt.get_type ()))) - : tl::nullopt; - auto init_expression - = stmt.has_init_expr () - ? tl::optional> (std::unique_ptr ( - ASTLoweringExpr::translate (stmt.get_init_expr ()))) - : tl::nullopt; + tl::optional> type = tl::nullopt; + + if (stmt.has_type ()) + type + = std::unique_ptr (ASTLoweringType::translate (stmt.get_type ())); + + tl::optional> init_expression = tl::nullopt; + + if (stmt.has_init_expr ()) + init_expression = std::unique_ptr ( + ASTLoweringExpr::translate (stmt.get_init_expr ())); auto crate_num = mappings.get_current_crate (); Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (),