diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-trait-resolve.cc | 22 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-trait-resolve.h | 40 |
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: |