Skip to content

Commit 3ccf008

Browse files
P-E-PCohenArthur
authored andcommitted
expand: Change names and document behavior
Change some argument name, as well as some documentation. gcc/rust/ChangeLog: * ast/rust-ast.cc (BlockExpr::normalize_tail_expr): Refactor code and warn about dangling reference. * expand/rust-expand-visitor.cc (expand_stmt_attribute): Document function and change argument names to make those clearer. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
1 parent be6d734 commit 3ccf008

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

gcc/rust/ast/rust-ast.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4228,8 +4228,10 @@ BlockExpr::normalize_tail_expr ()
42284228
if (!expr)
42294229
{
42304230
// HACK: try to turn the last statement into a tail expression
4231-
if (statements.size () && statements.back ()->is_expr ())
4231+
if (!statements.empty () && statements.back ()->is_expr ())
42324232
{
4233+
// Watch out: This reference become invalid when the vector is
4234+
// modified.
42334235
auto &stmt = static_cast<ExprStmt &> (*statements.back ());
42344236

42354237
if (!stmt.is_semicolon_followed ())

gcc/rust/expand/rust-expand-visitor.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,18 @@ expand_item_attribute (AST::Item &item, AST::SimplePath &name,
149149
return result;
150150
}
151151

152+
/* Helper function to expand a given attribute on a statement and collect back
153+
* statements.
154+
* T should be anything that can be used as a statement accepting outer
155+
* attributes.
156+
*/
152157
template <typename T>
153158
static std::vector<std::unique_ptr<AST::Stmt>>
154-
expand_stmt_attribute (T &item, AST::SimplePath &name, MacroExpander &expander)
159+
expand_stmt_attribute (T &statement, AST::SimplePath &attribute,
160+
MacroExpander &expander)
155161
{
156162
std::vector<std::unique_ptr<AST::Stmt>> result;
157-
auto frag = expander.expand_attribute_proc_macro (item, name);
163+
auto frag = expander.expand_attribute_proc_macro (statement, attribute);
158164
if (!frag.is_error ())
159165
{
160166
for (auto &node : frag.get_nodes ())

0 commit comments

Comments
 (0)