Skip to content

Commit

Permalink
nr1.0: Resolve lang item paths properly.
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Adapt resolver
	to lang item paths.
	* resolve/rust-ast-resolve-type.h: Likewise.
  • Loading branch information
CohenArthur committed Dec 5, 2024
1 parent 375896d commit eeedb0b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
31 changes: 24 additions & 7 deletions gcc/rust/resolve/rust-ast-resolve-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -678,16 +678,33 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
return;
}

// FIXME: Cleanup!
bool ok;

// setup paths
CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
canonical_trait_type);
if (!ok)
if (impl_block.get_trait_path ().get_path_kind ()
== AST::Path::Kind::LangItem)
{
resolver->get_name_scope ().pop ();
resolver->get_type_scope ().pop ();
resolver->get_label_scope ().pop ();
return;
auto &lang_item
= static_cast<AST::LangItemPath &> (impl_block.get_trait_path ());

canonical_trait_type
= CanonicalPath::new_seg (lang_item.get_node_id (),
LangItem::ToString (
lang_item.get_lang_item_kind ()));
}
else
{
ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
canonical_trait_type);
if (!ok)
{
resolver->get_name_scope ().pop ();
resolver->get_type_scope ().pop ();
resolver->get_label_scope ().pop ();
return;
}
}

rust_debug ("AST::TraitImpl resolve trait type: {%s}",
Expand Down
11 changes: 9 additions & 2 deletions gcc/rust/resolve/rust-ast-resolve-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

#include "rust-ast-resolve-base.h"
#include "rust-ast-resolve-expr.h"
#include "rust-diagnostics.h"
#include "rust-hir-map.h"
#include "rust-path.h"
#include "util/rust-hir-map.h"

namespace Rust {
namespace Resolver {
Expand Down Expand Up @@ -69,9 +71,14 @@ class ResolveType : public ResolverBase
{
auto &type = static_cast<AST::LangItemPath &> (type_path);

Analysis::Mappings::get_lang_item (type);
rust_debug ("[ARTHUR]: lang item kind: %s",
LangItem::ToString (type.get_lang_item_kind ()).c_str ());

type.get_node_id ();
auto lang_item = Analysis::Mappings::get ()
.lookup_lang_item_node (type.get_lang_item_kind ())
.value ();

return lang_item;
}

rust_assert (type_path.get_path_kind () == AST::Path::Kind::Type);
Expand Down

0 comments on commit eeedb0b

Please sign in to comment.