From: Arthur Cohen <[email protected]>
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::block): Change return type.
(Builder::loop): Use new APIs.
* ast/rust-ast-builder.h: Change return type of block functions.
---
gcc/rust/ast/rust-ast-builder.cc | 22 +++++++++++-----------
gcc/rust/ast/rust-ast-builder.h | 12 ++++++------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 369f5a44630..f59ff19d621 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -279,23 +279,25 @@ Builder::path_in_expression (LangItem::Kind lang_item)
const
return PathInExpression (lang_item, {}, loc);
}
-std::unique_ptr<Expr>
-Builder::block (std::unique_ptr<Stmt> &&stmt,
+std::unique_ptr<BlockExpr>
+Builder::block (tl::optional<std::unique_ptr<Stmt>> &&stmt,
std::unique_ptr<Expr> &&tail_expr) const
{
auto stmts = std::vector<std::unique_ptr<Stmt>> ();
- stmts.emplace_back (std::move (stmt));
+
+ if (stmt)
+ stmts.emplace_back (std::move (*stmt));
return block (std::move (stmts), std::move (tail_expr));
}
-std::unique_ptr<Expr>
+std::unique_ptr<BlockExpr>
Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr) const
{
- return std::unique_ptr<Expr> (new BlockExpr (std::move (stmts),
- std::move (tail_expr), {}, {},
- LoopLabel::error (), loc, loc));
+ return std::unique_ptr<BlockExpr> (
+ new BlockExpr (std::move (stmts), std::move (tail_expr), {}, {},
+ LoopLabel::error (), loc, loc));
}
std::unique_ptr<Expr>
@@ -421,11 +423,9 @@ Builder::match_case (std::unique_ptr<Pattern> &&pattern,
std::unique_ptr<Expr>
Builder::loop (std::vector<std::unique_ptr<Stmt>> &&stmts)
{
- auto block = std::unique_ptr<BlockExpr> (
- new BlockExpr (std::move (stmts), nullptr, {}, {}, LoopLabel::error (),
loc,
- loc));
+ auto block_expr = block (std::move (stmts), nullptr);
- return std::unique_ptr<Expr> (new LoopExpr (std::move (block), loc));
+ return std::unique_ptr<Expr> (new LoopExpr (std::move (block_expr), loc));
}
std::unique_ptr<TypeParamBound>
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index 99ab1610ce7..9fbcea182be 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -82,12 +82,12 @@ public:
std::unique_ptr<Expr> deref (std::unique_ptr<Expr> &&of) const;
/* Create a block with an optional tail expression */
- std::unique_ptr<Expr> block (std::vector<std::unique_ptr<Stmt>> &&stmts,
- std::unique_ptr<Expr> &&tail_expr
- = nullptr) const;
- std::unique_ptr<Expr> block (std::unique_ptr<Stmt> &&stmt,
- std::unique_ptr<Expr> &&tail_expr
- = nullptr) const;
+ std::unique_ptr<BlockExpr> block (std::vector<std::unique_ptr<Stmt>> &&stmts,
+ std::unique_ptr<Expr> &&tail_expr
+ = nullptr) const;
+ std::unique_ptr<BlockExpr> block (tl::optional<std::unique_ptr<Stmt>> &&stmt,
+ std::unique_ptr<Expr> &&tail_expr
+ = nullptr) const;
/* Create an early return expression with an optional expression */
std::unique_ptr<Expr> return_expr (std::unique_ptr<Expr> &&to_return
--
2.45.2