From: Philip Herron Date: Sun, 22 Aug 2021 12:44:46 +0000 (+0100) Subject: Add impl-trait path probe helper X-Git-Url: https://gcc.gnu.org/git/?a=commitdiff_plain;h=a6c8bd136dd4e89752eaec6415ba651f3cd73b9e;p=gcc.git Add impl-trait path probe helper This adds a probe to lookup candidates for a segment for any impl block for this receiver and trait. This simplifies some query based compilation code. When the item is resolved to a trait item but might be overriden by a reciever impl block instead. --- diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h index f737141d897c..60cd98a5e5ed 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.h +++ b/gcc/rust/typecheck/rust-hir-path-probe.h @@ -114,6 +114,7 @@ struct PathProbeCandidate class PathProbeType : public TypeCheckBase { +protected: using Rust::Resolver::TypeCheckBase::visit; public: @@ -207,7 +208,7 @@ public: } } -private: +protected: void process_impl_items_for_candidates () { mappings->iterate_impl_items ([&] (HirId id, HIR::ImplItem *item, @@ -313,7 +314,7 @@ private: } } -private: +protected: PathProbeType (const TyTy::BaseType *receiver, const HIR::PathIdentSegment &query) : TypeCheckBase (), receiver (receiver), search (query), @@ -404,6 +405,33 @@ private: RichLocation &r; }; +class PathProbeImplTrait : public PathProbeType +{ +public: + static std::vector + Probe (const TyTy::BaseType *receiver, + const HIR::PathIdentSegment &segment_name, + const TraitReference *trait_reference) + { + PathProbeImplTrait probe (receiver, segment_name, trait_reference); + // iterate all impls for this trait and receiver + // then search for possible candidates using base class behaviours + probe.process_trait_impl_items_for_candidates (); + return probe.candidates; + } + +private: + void process_trait_impl_items_for_candidates (); + + PathProbeImplTrait (const TyTy::BaseType *receiver, + const HIR::PathIdentSegment &query, + const TraitReference *trait_reference) + : PathProbeType (receiver, query), trait_reference (trait_reference) + {} + + const TraitReference *trait_reference; +}; + } // namespace Resolver } // namespace Rust