]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Change trait getter to return references
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 31 Jul 2023 10:31:58 +0000 (12:31 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:04:32 +0000 (19:04 +0100)
Having copy and any other constructor stuff might lead to a breakage in
the future where the node id differs due to a newly constructed
SimplePath node. This change will allow us to assert the NodeId is from
the ast and not any copy made in between.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::get_traits_to_derive): Change
return type to a vector of references.
* ast/rust-ast.h: Update constructor.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_stmts):
Update function call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-ast.h
gcc/rust/expand/rust-expand-visitor.cc

index 076f40e338b7b07c77c36b4e5073e4cdcff17c1f..3525a15beb5856bb0b0d5ac9ce24bf6bd50c306d 100644 (file)
@@ -95,15 +95,15 @@ Attribute::is_derive () const
  *
  * @param attrs The attributes on the item to derive
  */
-std::vector<AST::SimplePath>
+std::vector<std::reference_wrapper<AST::SimplePath>>
 Attribute::get_traits_to_derive ()
 {
-  std::vector<AST::SimplePath> result;
+  std::vector<std::reference_wrapper<AST::SimplePath>> result;
   auto &input = get_attr_input ();
   switch (input.get_attr_input_type ())
     {
       case AST::AttrInput::META_ITEM: {
-       auto meta = static_cast<AST::AttrInputMetaItemContainer &> (input);
+       auto &meta = static_cast<AST::AttrInputMetaItemContainer &> (input);
        for (auto &current : meta.get_items ())
          {
            // HACK: Find a better way to achieve the downcast.
index 32732ffdbd75a5b2087a8002fce3717bee10f889..136da86525d9d3b4f07968f7c8e607ab97dfd039 100644 (file)
@@ -519,7 +519,7 @@ public:
 
   bool is_derive () const;
 
-  std::vector<AST::SimplePath> get_traits_to_derive ();
+  std::vector<std::reference_wrapper<AST::SimplePath>> get_traits_to_derive ();
 
   // default destructor
   ~Attribute () = default;
index f75069b2e0a57e1f82578b4e7fdc430250e19bb6..55d5de0a04ecfee472bceec93d8638c4c6b2e859 100644 (file)
@@ -185,7 +185,7 @@ ExpandVisitor::expand_inner_items (
                  for (auto &to_derive : traits_to_derive)
                    {
                      auto maybe_builtin = MacroBuiltin::builtins.lookup (
-                       to_derive.as_string ());
+                       to_derive.get ().as_string ());
                      if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin))
                        {
                          auto new_item
@@ -271,7 +271,7 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr)
                  for (auto &to_derive : traits_to_derive)
                    {
                      auto maybe_builtin = MacroBuiltin::builtins.lookup (
-                       to_derive.as_string ());
+                       to_derive.get ().as_string ());
                      if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin))
                        {
                          auto new_item