diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-07-15 16:29:32 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-07-16 13:07:17 +0100 |
commit | f813b3309837f8fea19a0924f22a3f20a3ac8304 (patch) | |
tree | 1a5a01fb005e7baa73b6d4f6e3c0685ec5edab45 /gcc/rust | |
parent | d57f3b8af1498c7bb4b1eaea372270119e9845fd (diff) | |
download | gcc-f813b3309837f8fea19a0924f22a3f20a3ac8304.zip gcc-f813b3309837f8fea19a0924f22a3f20a3ac8304.tar.gz gcc-f813b3309837f8fea19a0924f22a3f20a3ac8304.tar.bz2 |
Track the parent impl a probe candidate comes from.
This change keeps an enum for the candidate type and the parent impl block
this probed candidate originates from.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-path-probe.h | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h index a10a562..1b7aa4d 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.h +++ b/gcc/rust/typecheck/rust-hir-path-probe.h @@ -29,8 +29,17 @@ namespace Resolver { struct PathProbeCandidate { + enum CandidateType + { + IMPL_CONST, + IMPL_TYPE_ALIAS, + IMPL_FUNC, + }; + + CandidateType type; HIR::ImplItem *impl_item; TyTy::BaseType *ty; + HIR::ImplBlock *parent; }; class PathProbeType : public TypeCheckBase @@ -48,11 +57,13 @@ public: probe.process_candidate (id, item, impl); return true; }); + return probe.candidates; } void process_candidate (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) { + current_impl = impl; HirId impl_ty_id = impl->get_type ()->get_mappings ().get_hirid (); TyTy::BaseType *impl_block_ty = nullptr; bool ok = context->lookup_type (impl_ty_id, &impl_block_ty); @@ -75,7 +86,9 @@ public: bool ok = context->lookup_type (tyid, &ty); rust_assert (ok); - PathProbeCandidate candidate{&alias, ty}; + PathProbeCandidate candidate{ + PathProbeCandidate::CandidateType::IMPL_TYPE_ALIAS, &alias, ty, + current_impl}; candidates.push_back (std::move (candidate)); } } @@ -90,7 +103,9 @@ public: bool ok = context->lookup_type (tyid, &ty); rust_assert (ok); - PathProbeCandidate candidate{&constant, ty}; + PathProbeCandidate candidate{ + PathProbeCandidate::CandidateType::IMPL_CONST, &constant, ty, + current_impl}; candidates.push_back (std::move (candidate)); } } @@ -105,19 +120,23 @@ public: bool ok = context->lookup_type (tyid, &ty); rust_assert (ok); - PathProbeCandidate candidate{&function, ty}; + PathProbeCandidate candidate{ + PathProbeCandidate::CandidateType::IMPL_FUNC, &function, ty, + current_impl}; candidates.push_back (std::move (candidate)); } } private: PathProbeType (TyTy::BaseType *receiver, const HIR::PathIdentSegment &query) - : TypeCheckBase (), receiver (receiver), search (query) + : TypeCheckBase (), receiver (receiver), search (query), + current_impl (nullptr) {} TyTy::BaseType *receiver; const HIR::PathIdentSegment &search; std::vector<PathProbeCandidate> candidates; + HIR::ImplBlock *current_impl; }; class ReportMultipleCandidateError : private TypeCheckBase |