aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-08-22 13:42:14 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-08-22 14:56:26 +0100
commitd5dd96322b588ffcf5bdd2fe0e3a14eb217d75b2 (patch)
tree6cc65a85f3761e6a07befee739179b2f100f3d6e /gcc
parentd609accab78269afe7fae509a0b7bb36d6e9d14e (diff)
downloadgcc-d5dd96322b588ffcf5bdd2fe0e3a14eb217d75b2.zip
gcc-d5dd96322b588ffcf5bdd2fe0e3a14eb217d75b2.tar.gz
gcc-d5dd96322b588ffcf5bdd2fe0e3a14eb217d75b2.tar.bz2
Add Trait Resolver simple type-path lookup
Post type checking we need to be able to lookup trait references, but do not need to resolve the trait with error messages. We simple want to look it up if it exists.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-trait-resolve.cc22
-rw-r--r--gcc/rust/typecheck/rust-hir-trait-resolve.h40
2 files changed, 62 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index cf3f2fb..aeedf7e 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -227,5 +227,27 @@ AssociatedImplTrait::get_projected_type (
return trait_item_tyty;
}
+// rust-hir-path-probe.h
+
+void
+PathProbeImplTrait::process_trait_impl_items_for_candidates ()
+{
+ mappings->iterate_impl_items (
+ [&] (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) mutable -> bool {
+ // just need to check if this is an impl block for this trait the next
+ // function checks the receiver
+ if (!impl->has_trait_ref ())
+ return true;
+
+ TraitReference *resolved
+ = TraitResolver::Lookup (*(impl->get_trait_ref ().get ()));
+ if (!trait_reference->is_equal (*resolved))
+ return true;
+
+ process_impl_item_candidate (id, item, impl);
+ return true;
+ });
+}
+
} // namespace Resolver
} // namespace Rust
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.h b/gcc/rust/typecheck/rust-hir-trait-resolve.h
index 6874a3a..0fe2406 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.h
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.h
@@ -72,6 +72,12 @@ public:
return resolver.go (path);
}
+ static TraitReference *Lookup (HIR::TypePath &path)
+ {
+ TraitResolver resolver;
+ return resolver.lookup_path (path);
+ }
+
private:
TraitResolver () : TypeCheckBase () {}
@@ -162,6 +168,40 @@ private:
return tref;
}
+ TraitReference *lookup_path (HIR::TypePath &path)
+ {
+ NodeId ref;
+ if (!resolver->lookup_resolved_type (path.get_mappings ().get_nodeid (),
+ &ref))
+ {
+ rust_error_at (path.get_locus (), "Failed to resolve path to node-id");
+ return &TraitReference::error_node ();
+ }
+
+ HirId hir_node = UNKNOWN_HIRID;
+ if (!mappings->lookup_node_to_hir (mappings->get_current_crate (), ref,
+ &hir_node))
+ {
+ rust_error_at (path.get_locus (), "Failed to resolve path to hir-id");
+ return &TraitReference::error_node ();
+ }
+
+ HIR::Item *resolved_item
+ = mappings->lookup_hir_item (mappings->get_current_crate (), hir_node);
+
+ rust_assert (resolved_item != nullptr);
+ resolved_item->accept_vis (*this);
+ rust_assert (trait_reference != nullptr);
+
+ TraitReference *tref = &TraitReference::error_node ();
+ if (context->lookup_trait_reference (
+ trait_reference->get_mappings ().get_defid (), &tref))
+ {
+ return tref;
+ }
+ return &TraitReference::error_node ();
+ }
+
HIR::Trait *trait_reference;
public: