aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-08-22 13:44:46 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-08-22 14:56:26 +0100
commita6c8bd136dd4e89752eaec6415ba651f3cd73b9e (patch)
treede6014aa7088f6cbd6614c7a132a0ff829215711 /gcc
parentd5dd96322b588ffcf5bdd2fe0e3a14eb217d75b2 (diff)
downloadgcc-a6c8bd136dd4e89752eaec6415ba651f3cd73b9e.zip
gcc-a6c8bd136dd4e89752eaec6415ba651f3cd73b9e.tar.gz
gcc-a6c8bd136dd4e89752eaec6415ba651f3cd73b9e.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-path-probe.h32
1 files changed, 30 insertions, 2 deletions
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h
index f737141..60cd98a 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<PathProbeCandidate>
+ 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