]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Improve canonical path handling for impl items
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 3 May 2025 00:28:15 +0000 (20:28 -0400)
committerPhilip Herron <philip.herron@embecosm.com>
Wed, 7 May 2025 15:33:20 +0000 (15:33 +0000)
gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Use the return values of
CanonicalPath::inherent_impl_seg and
CanonicalPath::trait_impl_projection_seg more directly.
* util/rust-canonical-path.h
(CanonicalPath::trait_impl_projection_seg): Append "<impl "
instead of "<" to the beginning of the returned path segment.
(CanonicalPath::inherent_impl_seg): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/resolve/rust-ast-resolve-item.cc
gcc/rust/util/rust-canonical-path.h

index fc226cf28c0a5c9dc4f95f99631192384acc4cf2..c2626ea0bbbf5fbfd8b01eb4e752bbad3b0b1eeb 100644 (file)
@@ -608,10 +608,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
     }
   else
     {
-      std::string seg_buf = "<impl " + self_cpath.get () + ">";
-      CanonicalPath seg
-       = CanonicalPath::new_seg (impl_block.get_node_id (), seg_buf);
-      cpath = canonical_prefix.append (seg);
+      cpath = canonical_prefix.append (impl_type_seg);
     }
 
   // done setup paths
@@ -732,13 +729,7 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
     }
   else
     {
-      std::string projection_str = canonical_projection.get ();
-      std::string seg_buf
-       = "<impl " + projection_str.substr (1, projection_str.size () - 2)
-         + ">";
-      CanonicalPath seg
-       = CanonicalPath::new_seg (impl_block.get_node_id (), seg_buf);
-      cpath = canonical_prefix.append (seg);
+      cpath = canonical_prefix.append (canonical_projection);
     }
 
   // DONE setup canonical-path
index 15846348f9c32131c0e333fb1b0f2ab2c208c765..33fead9c6c27e0dfb1b4b67ebadc04048af673d4 100644 (file)
@@ -68,14 +68,18 @@ public:
   trait_impl_projection_seg (NodeId id, const CanonicalPath &trait_seg,
                             const CanonicalPath &impl_type_seg)
   {
-    return CanonicalPath::new_seg (id, "<" + impl_type_seg.get () + " as "
+    // https://doc.rust-lang.org/reference/paths.html#canonical-paths
+    // should be "<X>"?
+    return CanonicalPath::new_seg (id, "<impl " + impl_type_seg.get () + " as "
                                         + trait_seg.get () + ">");
   }
 
   static CanonicalPath inherent_impl_seg (NodeId id,
                                          const CanonicalPath &impl_type_seg)
   {
-    return CanonicalPath::new_seg (id, "<" + impl_type_seg.get () + ">");
+    // https://doc.rust-lang.org/reference/paths.html#canonical-paths
+    // should be "<X as Y>"?
+    return CanonicalPath::new_seg (id, "<impl " + impl_type_seg.get () + ">");
   }
 
   std::string get () const