diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-11-05 12:32:44 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-11-05 12:45:32 +0000 |
commit | 17dc14cb4b0819532376a22b592b26dd6ffc364f (patch) | |
tree | 9286859b3eac842bcb0f76f1fc1d6ce987d488b6 /gcc/rust/resolve/rust-ast-resolve.cc | |
parent | d2f92e6a73338c986601a071b8641c051e700aba (diff) | |
download | gcc-17dc14cb4b0819532376a22b592b26dd6ffc364f.zip gcc-17dc14cb4b0819532376a22b592b26dd6ffc364f.tar.gz gcc-17dc14cb4b0819532376a22b592b26dd6ffc364f.tar.bz2 |
Support forward declared items within blocks
This changes the BlockExpr resolution to iterate Items first, then the
Stmts. This could be handled in HIR by desugaring the BlockExpr by lowering
the block into { <items>; <stmts>; } would also work. But the HIR lowering
of blocks is a little messy right now and we need to clean up the
unreachable lint.
Fixes #531
Diffstat (limited to 'gcc/rust/resolve/rust-ast-resolve.cc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 83a15a8..2758c83 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -349,7 +349,16 @@ ResolveExpr::visit (AST::BlockExpr &expr) resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); for (auto &s : expr.get_statements ()) - ResolveStmt::go (s.get (), s->get_node_id ()); + { + if (s->is_item ()) + ResolveStmt::go (s.get (), s->get_node_id ()); + } + + for (auto &s : expr.get_statements ()) + { + if (!s->is_item ()) + ResolveStmt::go (s.get (), s->get_node_id ()); + } if (expr.has_tail_expr ()) ResolveExpr::go (expr.get_tail_expr ().get (), expr.get_node_id ()); |