]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Specialize ExpandVisitor::expand_macro_children
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 19 Jul 2025 01:44:09 +0000 (21:44 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:57 +0000 (16:36 +0200)
gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc
(ExpandVisitor::expand_inner_items): Adjust call to
expand_macro_children.
(ExpandVisitor::expand_inner_stmts): Likewise.
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::expand_macro_children): Take a pointer to member
function instead of a std::function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/expand/rust-expand-visitor.h

index ba7bac12ddf4da6411817238d134f95b8198e164..69959b541c7f488a0fd5cc9a1ee6b5fcabe22c91 100644 (file)
@@ -233,10 +233,7 @@ ExpandVisitor::expand_inner_items (
        }
     }
 
-  std::function<std::unique_ptr<AST::Item> (AST::SingleASTNode)> extractor
-    = [] (AST::SingleASTNode node) { return node.take_item (); };
-
-  expand_macro_children (items, extractor);
+  expand_macro_children (items, &AST::SingleASTNode::take_item);
 
   expander.pop_context ();
 }
@@ -324,10 +321,7 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr)
   if (!expr.has_tail_expr ())
     expr.normalize_tail_expr ();
 
-  std::function<std::unique_ptr<AST::Stmt> (AST::SingleASTNode)> extractor
-    = [] (AST::SingleASTNode node) { return node.take_stmt (); };
-
-  expand_macro_children (stmts, extractor);
+  expand_macro_children (stmts, &AST::SingleASTNode::take_stmt);
 
   expander.pop_context ();
 }
@@ -866,12 +860,9 @@ ExpandVisitor::visit (AST::Trait &trait)
 
   expander.push_context (MacroExpander::ContextType::TRAIT);
 
-  std::function<std::unique_ptr<AST::AssociatedItem> (AST::SingleASTNode)>
-    extractor
-    = [] (AST::SingleASTNode node) { return node.take_assoc_item (); };
-
   expand_macro_children (MacroExpander::ContextType::TRAIT,
-                        trait.get_trait_items (), extractor);
+                        trait.get_trait_items (),
+                        &AST::SingleASTNode::take_assoc_item);
 
   expander.pop_context ();
 }
@@ -894,12 +885,9 @@ ExpandVisitor::visit (AST::InherentImpl &impl)
   if (impl.has_where_clause ())
     expand_where_clause (impl.get_where_clause ());
 
-  std::function<std::unique_ptr<AST::AssociatedItem> (AST::SingleASTNode)>
-    extractor
-    = [] (AST::SingleASTNode node) { return node.take_assoc_item (); };
-
   expand_macro_children (MacroExpander::ContextType::IMPL,
-                        impl.get_impl_items (), extractor);
+                        impl.get_impl_items (),
+                        &AST::SingleASTNode::take_assoc_item);
 }
 
 void
@@ -922,12 +910,9 @@ ExpandVisitor::visit (AST::TraitImpl &impl)
   if (impl.has_where_clause ())
     expand_where_clause (impl.get_where_clause ());
 
-  std::function<std::unique_ptr<AST::AssociatedItem> (AST::SingleASTNode)>
-    extractor
-    = [] (AST::SingleASTNode node) { return node.take_assoc_item (); };
-
   expand_macro_children (MacroExpander::ContextType::TRAIT_IMPL,
-                        impl.get_impl_items (), extractor);
+                        impl.get_impl_items (),
+                        &AST::SingleASTNode::take_assoc_item);
 }
 
 void
@@ -944,12 +929,10 @@ void
 ExpandVisitor::visit (AST::ExternBlock &block)
 {
   visit_inner_attrs (block);
-  std::function<std::unique_ptr<AST::ExternalItem> (AST::SingleASTNode)>
-    extractor
-    = [] (AST::SingleASTNode node) { return node.take_external_item (); };
 
   expand_macro_children (MacroExpander::ContextType::EXTERN,
-                        block.get_extern_items (), extractor);
+                        block.get_extern_items (),
+                        &AST::SingleASTNode::take_external_item);
 }
 
 void
index b82040c0878a92b43089e9604bb8ae4fed4f4032..ef78404ae6bce64a95b0c10b8d298874f11e5abc 100644 (file)
@@ -105,7 +105,7 @@ public:
    */
   template <typename T, typename U>
   void expand_macro_children (MacroExpander::ContextType ctx, T &values,
-                             std::function<U (AST::SingleASTNode)> extractor)
+                             U (AST::SingleASTNode::*extractor) (void))
   {
     expander.push_context (ctx);
 
@@ -121,7 +121,7 @@ public:
    */
   template <typename T, typename U>
   void expand_macro_children (T &values,
-                             std::function<U (AST::SingleASTNode)> extractor)
+                             U (AST::SingleASTNode::*extractor) (void))
   {
     for (auto it = values.begin (); it != values.end ();)
       {
@@ -138,7 +138,7 @@ public:
            it = values.erase (it);
            for (auto &node : final_fragment.get_nodes ())
              {
-               U new_node = extractor (node);
+               U new_node = (node.*extractor) ();
                if (new_node != nullptr)
                  {
                    it = values.insert (it, std::move (new_node));