aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-07-03 16:26:15 +0000
committerGitHub <noreply@github.com>2021-07-03 16:26:15 +0000
commit210ae4f7b0fea9671482b8f01354fd5b9274f878 (patch)
tree7724e51fcaee8a851c83a1337cb1c30b633bccbd /gcc
parent2b1d687d6a8eb959664e5299af229089341d14be (diff)
parente1aedf6ec7d30d957c96e8ac1e2eb1c7d1384242 (diff)
downloadgcc-210ae4f7b0fea9671482b8f01354fd5b9274f878.zip
gcc-210ae4f7b0fea9671482b8f01354fd5b9274f878.tar.gz
gcc-210ae4f7b0fea9671482b8f01354fd5b9274f878.tar.bz2
Merge #543
543: mark live symbol in if expr family except if let expr r=philberty a=thomasyonug mark live symbol in if expr family except if let expr Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/lint/rust-lint-marklive.h20
-rw-r--r--gcc/testsuite/rust/compile/torture/if.rs19
-rw-r--r--gcc/testsuite/rust/compile/torture/if_elif.rs20
-rw-r--r--gcc/testsuite/rust/compile/torture/if_else.rs19
4 files changed, 78 insertions, 0 deletions
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index 72274d0..5bc23e3 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -182,6 +182,26 @@ public:
expr.visit_rhs (*this);
}
+ void visit (HIR::IfExpr &expr) override
+ {
+ expr.get_if_condition ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ }
+
+ void visit (HIR::IfExprConseqElse &expr) override
+ {
+ expr.get_if_condition ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ expr.get_else_block ()->accept_vis (*this);
+ }
+
+ void visit (HIR::IfExprConseqIf &expr) override
+ {
+ expr.get_if_condition ()->accept_vis (*this);
+ expr.get_if_block ()->accept_vis (*this);
+ expr.get_conseq_if_expr ()->accept_vis (*this);
+ }
+
void visit (HIR::TraitItemFunc &item) override
{
item.get_block_expr ()->accept_vis (*this);
diff --git a/gcc/testsuite/rust/compile/torture/if.rs b/gcc/testsuite/rust/compile/torture/if.rs
new file mode 100644
index 0000000..bcd520f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/if.rs
@@ -0,0 +1,19 @@
+fn foo() -> bool {
+ true
+}
+
+fn bar() {}
+
+struct Foo1 {
+ one: i32
+}
+
+
+fn main() {
+ if foo() {
+ bar();
+ let a = Foo1{one: 1};
+ a.one
+ }
+
+} \ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/torture/if_elif.rs b/gcc/testsuite/rust/compile/torture/if_elif.rs
new file mode 100644
index 0000000..a89ad5e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/if_elif.rs
@@ -0,0 +1,20 @@
+fn foo() -> bool {
+ true
+}
+
+fn bar() -> bool {
+ false
+}
+
+struct Foo1 {
+ one: i32
+}
+
+
+fn main() {
+ if foo() {
+ } else if bar() {
+ let a = Foo1{one: 1};
+ a.one;
+ }
+} \ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/torture/if_else.rs b/gcc/testsuite/rust/compile/torture/if_else.rs
new file mode 100644
index 0000000..09aecae
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/if_else.rs
@@ -0,0 +1,19 @@
+fn foo() -> bool {
+ true
+}
+
+fn bar() {}
+
+struct Foo1 {
+ one: i32
+}
+
+
+fn main() {
+ if foo() {
+ bar();
+ } else {
+ let a = Foo1{one: 1};
+ a.one;
+ }
+} \ No newline at end of file