aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Young <wenzhang5800@gmail.com>2021-06-26 11:48:12 +0800
committerThomas Young <wenzhang5800@gmail.com>2021-06-26 12:00:08 +0800
commit5e63d163fe8c398d1953feae503d545e84c798bf (patch)
tree6762600966d68447c8fe16712d8dab24fd720eb9
parentc9cb0c3d446321e80b3c790b9ade0dda1574dc29 (diff)
downloadgcc-5e63d163fe8c398d1953feae503d545e84c798bf.zip
gcc-5e63d163fe8c398d1953feae503d545e84c798bf.tar.gz
gcc-5e63d163fe8c398d1953feae503d545e84c798bf.tar.bz2
mark live symbol in tuple expr
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h9
-rw-r--r--gcc/rust/lint/rust-lint-marklive.h16
-rw-r--r--gcc/testsuite/rust/compile/torture/tuple_function.rs6
3 files changed, 27 insertions, 4 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 102ab97..f718a61 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -1064,6 +1064,15 @@ public:
bool is_unit () const { return tuple_elems.size () == 0; }
+ void iterate (std::function<bool (Expr *)> cb)
+ {
+ for (auto &tuple_elem : tuple_elems)
+ {
+ if (!cb (tuple_elem.get ()))
+ return;
+ }
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index 46f0bb3..67dd76a 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -67,18 +67,26 @@ public:
void visit (HIR::GroupedExpr &expr) override
{
- expr.get_expr_in_parens()->accept_vis(*this);
+ expr.get_expr_in_parens ()->accept_vis (*this);
}
void visit (HIR::ArrayExpr &expr) override
{
- expr.get_internal_elements()->accept_vis(*this);
+ expr.get_internal_elements ()->accept_vis (*this);
}
void visit (HIR::ArrayElemsValues &expr) override
{
- expr.iterate([&](HIR::Expr *expr) mutable -> bool {
- expr->accept_vis(*this);
+ expr.iterate ([&] (HIR::Expr *expr) mutable -> bool {
+ expr->accept_vis (*this);
+ return true;
+ });
+ }
+
+ void visit (HIR::TupleExpr &expr) override
+ {
+ expr.iterate ([&] (HIR::Expr *expr) mutable -> bool {
+ expr->accept_vis (*this);
return true;
});
}
diff --git a/gcc/testsuite/rust/compile/torture/tuple_function.rs b/gcc/testsuite/rust/compile/torture/tuple_function.rs
new file mode 100644
index 0000000..514b586
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/tuple_function.rs
@@ -0,0 +1,6 @@
+fn foo() -> i32 {
+ return 1;
+}
+fn main() {
+ let _a = (foo(), 2);
+}