Skip to content

Commit

Permalink
Refactor optional initializers
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
P-E-P committed Nov 19, 2024
1 parent 1415528 commit 26fdda1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions gcc/rust/hir/rust-ast-lower-stmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 (),
Expand Down

0 comments on commit 26fdda1

Please sign in to comment.