Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CanonicalPath for impl #2633

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gcc/rust/resolve/rust-ast-resolve-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down
8 changes: 6 additions & 2 deletions gcc/rust/resolve/rust-ast-resolve-toplevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_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);
Expand Down
6 changes: 6 additions & 0 deletions gcc/rust/util/rust-canonical-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading