From a5e46521f33d4ea0287221eb63c89a12580c076c Mon Sep 17 00:00:00 2001 From: Raiki Tamura Date: Wed, 20 Sep 2023 13:42:02 +0900 Subject: [PATCH] Fix CanonicalPath for inherent impl 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 --- gcc/rust/resolve/rust-ast-resolve-item.cc | 5 ++++- gcc/rust/resolve/rust-ast-resolve-toplevel.h | 8 ++++++-- gcc/rust/util/rust-canonical-path.h | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 52adde8e8ee3..f711e64e70b1 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -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,7 +577,9 @@ 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 (); diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 9ba8bdb5caff..b17255e186bb 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -344,10 +344,14 @@ class ResolveTopLevel : public ResolverBase 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_type ()->get_node_id (), impl_type_seg); + rust_debug ("<%s>", impl_type_seg.get ().c_str ()); + CanonicalPath impl_prefix = prefix.append (impl_type_seg); for (auto &impl_item : impl_block.get_impl_items ()) ResolveToplevelImplItem::go (impl_item.get (), impl_prefix); diff --git a/gcc/rust/util/rust-canonical-path.h b/gcc/rust/util/rust-canonical-path.h index 2f28302c1c14..8c275a77953c 100644 --- a/gcc/rust/util/rust-canonical-path.h +++ b/gcc/rust/util/rust-canonical-path.h @@ -69,6 +69,12 @@ class CanonicalPath + 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;