aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-05-23 09:30:59 +0000
committerGitHub <noreply@github.com>2022-05-23 09:30:59 +0000
commit9204e7a1ac617126b65c27668524aebf8f65f134 (patch)
treeaf165c5f411991f165a76ffe2a02766b5195d679 /gcc
parent55ec3454d0d45829431d8904aa0b6363ac362616 (diff)
parentdccb3f8121e416009dae6e5b8f675603d2a0503d (diff)
downloadgcc-9204e7a1ac617126b65c27668524aebf8f65f134.zip
gcc-9204e7a1ac617126b65c27668524aebf8f65f134.tar.gz
gcc-9204e7a1ac617126b65c27668524aebf8f65f134.tar.bz2
Merge #1267
1267: Marklive: support match expr r=philberty a=thomasyonug This makes `MarkLive` support `HIR::MatchExpr` and adds a related test case. Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h6
-rw-r--r--gcc/rust/lint/rust-lint-marklive.h13
-rw-r--r--gcc/testsuite/rust/compile/match6.rs18
3 files changed, 37 insertions, 0 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index e585dd2..f6f035e 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -3842,6 +3842,12 @@ public:
return match_arm_patterns;
}
+ std::unique_ptr<Expr> &get_guard_expr ()
+ {
+ rust_assert (has_match_arm_guard ());
+ return guard_expr;
+ }
+
Location get_locus () const { return locus; }
};
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index aeecda5..529afa6 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -204,6 +204,19 @@ public:
expr.get_else_block ()->accept_vis (*this);
}
+ void visit (HIR::MatchExpr &expr) override
+ {
+ expr.get_scrutinee_expr ()->accept_vis (*this);
+ std::vector<HIR::MatchCase> &cases = expr.get_match_cases ();
+ for (auto &&caz : cases)
+ {
+ auto case_arm = caz.get_arm ();
+ if (case_arm.has_match_arm_guard ())
+ case_arm.get_guard_expr ()->accept_vis (*this);
+ caz.get_expr ()->accept_vis (*this);
+ }
+ }
+
void visit (HIR::IfExprConseqIf &expr) override
{
expr.get_if_condition ()->accept_vis (*this);
diff --git a/gcc/testsuite/rust/compile/match6.rs b/gcc/testsuite/rust/compile/match6.rs
new file mode 100644
index 0000000..8fe06f7
--- /dev/null
+++ b/gcc/testsuite/rust/compile/match6.rs
@@ -0,0 +1,18 @@
+fn foo() -> bool {
+ true
+}
+
+fn int32() -> i32 {
+ 1
+}
+
+fn bar() -> i32 {
+ match foo() {
+ true => int32(),
+ false => 0
+ }
+}
+
+fn main() -> () {
+ bar();
+} \ No newline at end of file