Skip to content

Commit 4239b70

Browse files
lucasly-baCohenArthur
authored andcommitted
gccrs: remove match arm pattern vector to single pattern
This patch refactors all uses of vector patterns since a vector of patterns would be considered as an alt pattern, a vector is considered useless. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::match_arm): Moves the vector of patterns to a single pattern. * ast/rust-ast-collector.cc (TokenCollector::visit):Likewise. * ast/rust-ast-pointer-visitor.cc (PointerVisitor::visit):Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):Likewise. * ast/rust-ast.cc (IfLetExpr::as_string):Likewise. (WhileLetLoopExpr::as_string):Likewise. (MatchArm::as_string):Likewise. * ast/rust-desugar-question-mark.cc (make_match_arm):Likewise. * ast/rust-desugar-while-let.cc (DesugarWhileLet::desugar):Likewise. * ast/rust-expr.h (class WhileLetLoopExpr):Likewise. (class IfLetExpr):Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit):Likewise. * checks/errors/rust-hir-pattern-analysis.cc (lower_arm):Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit):Likewise. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet):Likewise. (ASTLoweringExprWithBlock::visit):Likewise. * hir/rust-hir-dump.cc (Dump::do_matcharm):Likewise. (Dump::visit):Likewise. * hir/tree/rust-hir-expr.cc (OperatorExpr::operator=):Likewise. (ArithmeticOrLogicalExpr::operator=):Likewise. (ComparisonExpr::operator=):Likewise. (LazyBooleanExpr::operator=):Likewise. (TypeCastExpr::operator=):Likewise. (AssignmentExpr::operator=):Likewise. (CompoundAssignmentExpr::operator=):Likewise. (GroupedExpr::operator=):Likewise. (ArrayExpr::operator=):Likewise. (ArrayIndexExpr::operator=):Likewise. (CallExpr::operator=):Likewise. (MethodCallExpr::operator=):Likewise. (FieldAccessExpr::operator=):Likewise. (BlockExpr::operator=):Likewise. (BreakExpr::operator=):Likewise. (ReturnExpr::operator=):Likewise. (UnsafeBlockExpr::operator=):Likewise. (BaseLoopExpr::operator=):Likewise. (WhileLetLoopExpr::WhileLetLoopExpr):Likewise. (WhileLetLoopExpr::operator=):Likewise. (MatchArm::MatchArm):Likewise. (MatchArm::operator=):Likewise. (MatchExpr::operator=):Likewise. * hir/tree/rust-hir-expr.h (class WhileLetLoopExpr):Likewise. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk):Likewise. (DefaultHIRVisitor::visit_match_arm):Likewise. * hir/tree/rust-hir.cc (WhileLetLoopExpr::as_string):Likewise. (MatchArm::as_string):Likewise. * parse/rust-parse-impl-expr.hxx: Likewise. * parse/rust-parse-impl.hxx: Likewise. * parse/rust-parse.h:Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit_if_let_patterns):Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit):Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):Likewise. Signed-off-by: Lucas Ly Ba <[email protected]>
1 parent 11c436c commit 4239b70

23 files changed

+194
-359
lines changed

gcc/rust/ast/rust-ast-builder.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,7 @@ Builder::match (std::unique_ptr<Expr> &&scrutinee,
484484
MatchArm
485485
Builder::match_arm (std::unique_ptr<Pattern> &&pattern)
486486
{
487-
auto patterns = std::vector<std::unique_ptr<Pattern>> ();
488-
patterns.emplace_back (std::move (pattern));
489-
490-
return MatchArm (std::move (patterns), loc);
487+
return MatchArm (std::move (pattern), loc);
491488
}
492489

493490
MatchCase

gcc/rust/ast/rust-ast-collector.cc

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,11 +1617,7 @@ TokenCollector::visit (WhileLetLoopExpr &expr)
16171617
visit_loop_common (expr);
16181618
push (Rust::Token::make (WHILE, expr.get_locus ()));
16191619
push (Rust::Token::make (LET, UNDEF_LOCATION));
1620-
// TODO: The reference mention only one Pattern
1621-
for (auto &item : expr.get_patterns ())
1622-
{
1623-
visit (item);
1624-
}
1620+
visit (expr.get_pattern ());
16251621
push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
16261622
visit (expr.get_scrutinee_expr ());
16271623
visit (expr.get_loop_block ());
@@ -1669,10 +1665,7 @@ TokenCollector::visit (IfLetExpr &expr)
16691665
describe_node (std::string ("IfLetExpr"), [this, &expr] () {
16701666
push (Rust::Token::make (IF, expr.get_locus ()));
16711667
push (Rust::Token::make (LET, UNDEF_LOCATION));
1672-
for (auto &pattern : expr.get_patterns ())
1673-
{
1674-
visit (pattern);
1675-
}
1668+
visit (expr.get_pattern ());
16761669
push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
16771670
visit (expr.get_value_expr ());
16781671
visit (expr.get_if_block ());
@@ -1695,10 +1688,7 @@ TokenCollector::visit (MatchArm &arm)
16951688
{
16961689
describe_node (std::string ("MatchArm"), [this, &arm] () {
16971690
visit_items_as_lines (arm.get_outer_attrs ());
1698-
for (auto &pattern : arm.get_patterns ())
1699-
{
1700-
visit (pattern);
1701-
}
1691+
visit (arm.get_pattern ());
17021692
if (arm.has_match_arm_guard ())
17031693
{
17041694
push (Rust::Token::make (IF, UNDEF_LOCATION));

gcc/rust/ast/rust-ast-pointer-visitor.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,7 @@ void
587587
PointerVisitor::visit (AST::WhileLetLoopExpr &expr)
588588
{
589589
visit_outer_attrs (expr);
590-
for (auto &pattern : expr.get_patterns ())
591-
reseat (pattern);
590+
reseat (expr.get_pattern ());
592591

593592
if (expr.has_loop_label ())
594593
visit (expr.get_loop_label ());
@@ -627,8 +626,7 @@ void
627626
PointerVisitor::visit (AST::IfLetExpr &expr)
628627
{
629628
visit_outer_attrs (expr);
630-
for (auto &pattern : expr.get_patterns ())
631-
reseat (pattern);
629+
reseat (expr.get_pattern ());
632630
reseat (expr.get_value_expr_ptr ());
633631
visit (expr.get_if_block ());
634632
}
@@ -644,8 +642,7 @@ void
644642
PointerVisitor::visit (AST::MatchArm &arm)
645643
{
646644
visit_outer_attrs (arm);
647-
for (auto &pattern : arm.get_patterns ())
648-
reseat (pattern);
645+
reseat (arm.get_pattern ());
649646
if (arm.has_match_arm_guard ())
650647
reseat (arm.get_guard_expr_ptr ());
651648
}

gcc/rust/ast/rust-ast-visitor.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,7 @@ void
607607
DefaultASTVisitor::visit (AST::WhileLetLoopExpr &expr)
608608
{
609609
visit_outer_attrs (expr);
610-
for (auto &pattern : expr.get_patterns ())
611-
visit (pattern);
610+
visit (expr.get_pattern ());
612611

613612
if (expr.has_loop_label ())
614613
visit (expr.get_loop_label ());
@@ -647,8 +646,7 @@ void
647646
DefaultASTVisitor::visit (AST::IfLetExpr &expr)
648647
{
649648
visit_outer_attrs (expr);
650-
for (auto &pattern : expr.get_patterns ())
651-
visit (pattern);
649+
visit (expr.get_pattern ());
652650
visit (expr.get_value_expr ());
653651
visit (expr.get_if_block ());
654652
}
@@ -664,8 +662,7 @@ void
664662
DefaultASTVisitor::visit (AST::MatchArm &arm)
665663
{
666664
visit_outer_attrs (arm);
667-
for (auto &pattern : arm.get_patterns ())
668-
visit (pattern);
665+
visit (arm.get_pattern ());
669666
if (arm.has_match_arm_guard ())
670667
visit (arm.get_guard_expr ());
671668
}

gcc/rust/ast/rust-ast.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,14 +1943,13 @@ IfLetExpr::as_string () const
19431943
str += append_attributes (outer_attrs, OUTER);
19441944

19451945
str += "\n Condition match arm patterns: ";
1946-
if (match_arm_patterns.empty ())
1946+
if (match_arm_pattern == nullptr)
19471947
{
19481948
str += "none";
19491949
}
19501950
else
19511951
{
1952-
for (const auto &pattern : match_arm_patterns)
1953-
str += "\n " + pattern->as_string ();
1952+
str += "\n " + match_arm_pattern->as_string ();
19541953
}
19551954

19561955
str += "\n Scrutinee expr: " + value->as_string ();
@@ -2167,14 +2166,13 @@ WhileLetLoopExpr::as_string () const
21672166
str += get_loop_label ().as_string ();
21682167

21692168
str += "\n Match arm patterns: ";
2170-
if (match_arm_patterns.empty ())
2169+
if (match_arm_pattern == nullptr)
21712170
{
21722171
str += "none";
21732172
}
21742173
else
21752174
{
2176-
for (const auto &pattern : match_arm_patterns)
2177-
str += "\n " + pattern->as_string ();
2175+
str += "\n " + match_arm_pattern->as_string ();
21782176
}
21792177

21802178
str += "\n Scrutinee expr: " + scrutinee->as_string ();
@@ -2253,14 +2251,13 @@ MatchArm::as_string () const
22532251
std::string str = append_attributes (outer_attrs, OUTER);
22542252

22552253
str += "\nPatterns: ";
2256-
if (match_arm_patterns.empty ())
2254+
if (match_arm_pattern == nullptr)
22572255
{
22582256
str += "none";
22592257
}
22602258
else
22612259
{
2262-
for (const auto &pattern : match_arm_patterns)
2263-
str += "\n " + pattern->as_string ();
2260+
str += "\n " + match_arm_pattern->as_string ();
22642261
}
22652262

22662263
str += "\nGuard expr: ";

gcc/rust/ast/rust-desugar-question-mark.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ MatchArm
3939
make_match_arm (std::unique_ptr<Pattern> &&pattern)
4040
{
4141
auto loc = pattern->get_locus ();
42-
43-
auto patterns = std::vector<std::unique_ptr<Pattern>> ();
44-
patterns.emplace_back (std::move (pattern));
45-
46-
return MatchArm (std::move (patterns), loc);
42+
return MatchArm (std::move (pattern), loc);
4743
}
4844

4945
MatchCase

gcc/rust/ast/rust-desugar-while-let.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ DesugarWhileLet::DesugarCtx::make_continue_arm (
5353
std::unique_ptr<Expr>
5454
DesugarWhileLet::desugar (WhileLetLoopExpr &expr)
5555
{
56-
rust_assert (expr.get_patterns ().size () == 1);
56+
rust_assert (expr.get_pattern () != nullptr);
5757

58-
auto pattern = expr.get_patterns ()[0]->clone_pattern ();
58+
auto pattern = expr.get_pattern ()->clone_pattern ();
5959
auto body = expr.get_loop_block ().clone_block_expr ();
6060
auto scrutinee = expr.get_scrutinee_expr ().clone_expr ();
6161

0 commit comments

Comments
 (0)