https://gcc.gnu.org/g:f95ca338eccb99f0b14ae9484e9614b9cfb333e0

commit f95ca338eccb99f0b14ae9484e9614b9cfb333e0
Author: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>
Date:   Wed Feb 7 12:51:28 2024 +0100

    Reinject Self parameter in new resolver
    
    The old resolver injected a Self generic parameter in order to help the
    trait solver. This is clearly sketchy at best and should be fixed in
    the future.
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
            Self generic parameter injection and a warning.
            * resolve/rust-toplevel-name-resolver-2.0.h: Add function prototype.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>

Diff:
---
 .../resolve/rust-toplevel-name-resolver-2.0.cc     | 23 ++++++++++++++++++++++
 gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h |  1 +
 2 files changed, 24 insertions(+)

diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index f65ec77331ce..80b142678b95 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -186,6 +186,29 @@ TopLevel::visit (AST::Module &module)
     Analysis::Mappings::get ()->insert_ast_module (&module);
 }
 
+void
+TopLevel::visit (AST::Trait &trait)
+{
+  // FIXME: This Self injection is dodgy. It even lead to issues with metadata
+  // export in the past (#2349). We cannot tell appart injected parameters from
+  // regular ones. Dumping generic parameters highlights this Self in metadata,
+  // during debug or proc macro collection. This is clearly a hack.
+  //
+  // For now I'll keep it here in the new name resolver even if it should
+  // probably not be there. We need to find another way to solve this.
+  // Maybe an additional attribute to Trait ?
+  //
+  // From old resolver:
+  //// we need to inject an implicit self TypeParam here
+  //// FIXME: which location should be used for Rust::Identifier `Self`?
+  AST::TypeParam *implicit_self
+    = new AST::TypeParam ({"Self"}, trait.get_locus ());
+  trait.insert_implict_self (
+    std::unique_ptr<AST::GenericParam> (implicit_self));
+
+  DefaultResolver::visit (trait);
+}
+
 template <typename PROC_MACRO>
 static void
 insert_macros (std::vector<PROC_MACRO> &macros, NameResolutionContext &ctx)
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h 
b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
index f5e224fa0499..e226c79dfbcd 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
@@ -88,6 +88,7 @@ private:
   std::unordered_map<NodeId, NodeId> node_forwarding;
 
   void visit (AST::Module &module) override;
+  void visit (AST::Trait &trait) override;
   void visit (AST::MacroRulesDefinition &macro) override;
   void visit (AST::Function &function) override;
   void visit (AST::BlockExpr &expr) override;

Reply via email to