aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-10-05 17:24:26 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-02-21 12:36:32 +0100
commit31b77593edbf623fb8f84e35baeb927fdd7c55b6 (patch)
tree083eabe2a4f749680663d53cbb20639186992d46 /gcc/rust/backend
parent79434fabf762d60b7aa54e2319c44c1610dd8065 (diff)
downloadgcc-31b77593edbf623fb8f84e35baeb927fdd7c55b6.zip
gcc-31b77593edbf623fb8f84e35baeb927fdd7c55b6.tar.gz
gcc-31b77593edbf623fb8f84e35baeb927fdd7c55b6.tar.bz2
gccrs: Ensure uniqueness on Path probe's
When we lookup names in paths such as Foo::bar, foo is a type we resolve and then we lookup 'bar' based on what type Foo is which includes probing relevant bounds of this type. We currently return a vector of possible candidates and this patch changes it so that we return a set of unique items based on DefId. Addresses #1555 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::resolve_method_address): Use auto and minor change in candidate init. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-type.cc: Likewise. * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Likewise. Removecall to set_ty_ref. * typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): Add locus initializer in ctor, implement get_defid. (class PathProbeType::Probe): return a set instead of vector. Adjust class impl. (class ReportMultipleCandidateError): Do not inherit from HIRImplVisitor anymore and remove corresponding impl. Adjust for change in Probe. Simplify Report handling. (class PathProbeImplTrait::Probe): Adjust return type.
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc4
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc8
2 files changed, 6 insertions, 6 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index d58e225..ddf914f 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1982,7 +1982,7 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
// trait-impl-item's definition
auto root = receiver->get_root ();
- std::vector<Resolver::PathProbeCandidate> candidates
+ auto candidates
= Resolver::PathProbeType::Probe (root, segment, true /* probe_impls */,
false /* probe_bounds */,
true /* ignore_mandatory_trait_items */);
@@ -2011,7 +2011,7 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
// implementation and we should just return error_mark_node
rust_assert (candidates.size () == 1);
- auto &candidate = candidates.at (0);
+ auto &candidate = *candidates.begin ();
rust_assert (candidate.is_impl_candidate ());
rust_assert (candidate.ty->get_kind () == TyTy::TypeKind::FNDEF);
TyTy::FnType *candidate_call = static_cast<TyTy::FnType *> (candidate.ty);
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 2cc9505..ab8e628 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -251,7 +251,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
// item so its up to us to figure out if this path should resolve
// to an trait-impl-block-item or if it can be defaulted to the
// trait-impl-item's definition
- std::vector<Resolver::PathProbeCandidate> candidates
+ auto candidates
= Resolver::PathProbeImplTrait::Probe (receiver, final_segment,
trait_ref);
if (candidates.size () == 0)
@@ -270,7 +270,9 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
}
else
{
- Resolver::PathProbeCandidate &candidate = candidates.at (0);
+ rust_assert (candidates.size () == 1);
+
+ auto candidate = *candidates.begin ();
rust_assert (candidate.is_impl_candidate ());
HIR::ImplBlock *impl = candidate.item.impl.parent;
@@ -288,8 +290,6 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
else
return CompileInherentImplItem::Compile (impl_item, ctx, lookup,
true, expr_locus);
-
- lookup->set_ty_ref (impl_item->get_impl_mappings ().get_hirid ());
}
}
}