aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse-impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h32
1 files changed, 28 insertions, 4 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index c95afd6..25979ce 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -8563,7 +8563,11 @@ Parser<ManagedTokenSource>::parse_match_expr (AST::AttrVec outer_attrs,
return nullptr;
}
- std::unique_ptr<AST::Expr> expr = parse_expr ();
+ ParseRestrictions restrictions;
+ restrictions.expr_can_be_stmt = true;
+ restrictions.consume_semi = false;
+
+ std::unique_ptr<AST::ExprStmt> expr = parse_expr_stmt ({}, restrictions);
if (expr == nullptr)
{
Error error (lexer.peek_token ()->get_locus (),
@@ -8573,10 +8577,30 @@ Parser<ManagedTokenSource>::parse_match_expr (AST::AttrVec outer_attrs,
// skip somewhere?
return nullptr;
}
- bool is_expr_without_block = expr->is_expr_without_block ();
+ bool is_expr_without_block
+ = expr->get_type () == AST::ExprStmt::ExprStmtType::WITHOUT_BLOCK;
// construct match case expr and add to cases
- match_arms.push_back (AST::MatchCase (std::move (arm), std::move (expr)));
+ switch (expr->get_type ())
+ {
+ case AST::ExprStmt::ExprStmtType::WITH_BLOCK: {
+ AST::ExprStmtWithBlock *cast
+ = static_cast<AST::ExprStmtWithBlock *> (expr.get ());
+ std::unique_ptr<AST::Expr> e = cast->get_expr ()->clone_expr ();
+ match_arms.push_back (
+ AST::MatchCase (std::move (arm), std::move (e)));
+ }
+ break;
+
+ case AST::ExprStmt::ExprStmtType::WITHOUT_BLOCK: {
+ AST::ExprStmtWithoutBlock *cast
+ = static_cast<AST::ExprStmtWithoutBlock *> (expr.get ());
+ std::unique_ptr<AST::Expr> e = cast->get_expr ()->clone_expr ();
+ match_arms.push_back (
+ AST::MatchCase (std::move (arm), std::move (e)));
+ }
+ break;
+ }
// handle comma presence
if (lexer.peek_token ()->get_id () != COMMA)
@@ -10400,7 +10424,7 @@ Parser<ManagedTokenSource>::parse_literal_or_range_pattern ()
// literal pattern
return std::unique_ptr<AST::LiteralPattern> (
new AST::LiteralPattern (range_lower->get_str (), type,
- range_lower->get_locus (), has_minus));
+ range_lower->get_locus ()));
}
}