]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: expand: Change names and document behavior
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 21 Jun 2023 13:56:26 +0000 (15:56 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:46:29 +0000 (18:46 +0100)
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 <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ast/rust-ast.cc
gcc/rust/expand/rust-expand-visitor.cc

index 2eac09ba5d37c905b9477d0735fc9c64a4070452..14ad3a05620e2441799560ddf8af613a15f6d529 100644 (file)
@@ -4228,8 +4228,10 @@ BlockExpr::normalize_tail_expr ()
   if (!expr)
     {
       // HACK: try to turn the last statement into a tail expression
-      if (statements.size () && statements.back ()->is_expr ())
+      if (!statements.empty () && statements.back ()->is_expr ())
        {
+         // Watch out: This reference become invalid when the vector is
+         // modified.
          auto &stmt = static_cast<ExprStmt &> (*statements.back ());
 
          if (!stmt.is_semicolon_followed ())
index 28ff3df314870193a1cfa940900cd1ef34ed2ddd..055f723fc75faf016f9ab60540e60e1ebdb5861f 100644 (file)
@@ -149,12 +149,18 @@ expand_item_attribute (AST::Item &item, AST::SimplePath &name,
   return result;
 }
 
+/* Helper function to expand a given attribute on a statement and collect back
+ * statements.
+ * T should be anything that can be used as a statement accepting outer
+ * attributes.
+ */
 template <typename T>
 static std::vector<std::unique_ptr<AST::Stmt>>
-expand_stmt_attribute (T &item, AST::SimplePath &name, MacroExpander &expander)
+expand_stmt_attribute (T &statement, AST::SimplePath &attribute,
+                      MacroExpander &expander)
 {
   std::vector<std::unique_ptr<AST::Stmt>> result;
-  auto frag = expander.expand_attribute_proc_macro (item, name);
+  auto frag = expander.expand_attribute_proc_macro (statement, attribute);
   if (!frag.is_error ())
     {
       for (auto &node : frag.get_nodes ())