]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix CanonicalPath for inherent impl
authorRaiki Tamura <tamaron1203@gmail.com>
Wed, 20 Sep 2023 04:42:02 +0000 (13:42 +0900)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:04:37 +0000 (19:04 +0100)
gcc/rust/ChangeLog:

* util/rust-canonical-path.h: Add new segment kind for inherent impl.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Use it.
* resolve/rust-ast-resolve-toplevel.h: Use it.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
gcc/rust/resolve/rust-ast-resolve-item.cc
gcc/rust/resolve/rust-ast-resolve-toplevel.h
gcc/rust/util/rust-canonical-path.h

index 1dee98ab00356a6ad8f3ed85f2999118ff859170..48682f0049f0a3f587039fa80dc632dfe25e4735 100644 (file)
@@ -565,6 +565,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
 
   // FIXME this needs to be protected behind nominal type-checks see:
   // rustc --explain E0118
+  // issue #2634
   ResolveType::go (impl_block.get_type ().get ());
 
   // Setup paths
@@ -576,13 +577,15 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
              self_cpath.get ().c_str ());
 
   CanonicalPath impl_type = self_cpath;
-  CanonicalPath impl_prefix = prefix.append (impl_type);
+  CanonicalPath impl_type_seg
+    = CanonicalPath::inherent_impl_seg (impl_block.get_node_id (), impl_type);
+  CanonicalPath impl_prefix = prefix.append (impl_type_seg);
 
   // see https://godbolt.org/z/a3vMbsT6W
   CanonicalPath cpath = CanonicalPath::create_empty ();
   if (canonical_prefix.size () <= 1)
     {
-      cpath = self_cpath;
+      cpath = impl_prefix;
     }
   else
     {
index 88d034b78698fe9e3dc65e1fa3b72f6a3ec6d2a4..73b4d29f19c655ae54bbbe5e9d926b2bf846f66b 100644 (file)
@@ -344,10 +344,14 @@ public:
   void visit (AST::InherentImpl &impl_block) override
   {
     std::string raw_impl_type_path = impl_block.get_type ()->as_string ();
-    CanonicalPath impl_type
+    CanonicalPath impl_type_seg
       = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (),
                                raw_impl_type_path);
-    CanonicalPath impl_prefix = prefix.append (impl_type);
+
+    CanonicalPath impl_type
+      = CanonicalPath::inherent_impl_seg (impl_block.get_node_id (),
+                                         impl_type_seg);
+    CanonicalPath impl_prefix = prefix.append (impl_type_seg);
 
     for (auto &impl_item : impl_block.get_impl_items ())
       ResolveToplevelImplItem::go (impl_item.get (), impl_prefix);
index a524feaea1a0cce9b4925ebb87a90c1c8a21faa4..f2865eba9ae407cf364c8da9d4304107f5308bd2 100644 (file)
@@ -69,6 +69,12 @@ public:
                                         + trait_seg.get () + ">");
   }
 
+  static CanonicalPath inherent_impl_seg (NodeId id,
+                                         const CanonicalPath &impl_type_seg)
+  {
+    return CanonicalPath::new_seg (id, "<" + impl_type_seg.get () + ">");
+  }
+
   std::string get () const
   {
     std::string buf;