From db24e859d8f0141ba97d828deed7cd0d0ae9a43d Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Sun, 22 Aug 2021 14:34:14 +0100 Subject: Path resolution is done in two phases This changes Path resolution to check for impl items first, then extensions second. This stops some invalid multiple canidate errors such as the case when the trait implements a function but the reciever also implements it to override the behaviour. --- gcc/rust/typecheck/rust-hir-type-check-path.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 657c45c..df45e66 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -348,17 +348,26 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, bool probe_impls = !reciever_is_generic; bool ignore_mandatory_trait_items = !reciever_is_generic; - // probe the path + // probe the path is done in two parts one where we search impls if no + // candidate is found then we search extensions from traits auto candidates = PathProbeType::Probe (prev_segment, seg.get_segment (), probe_impls, - probe_bounds, ignore_mandatory_trait_items); + false, ignore_mandatory_trait_items); if (candidates.size () == 0) { - rust_error_at (seg.get_locus (), - "failed to resolve path segment using an impl Probe"); - return; + candidates + = PathProbeType::Probe (prev_segment, seg.get_segment (), false, + probe_bounds, ignore_mandatory_trait_items); + if (candidates.size () == 0) + { + rust_error_at ( + seg.get_locus (), + "failed to resolve path segment using an impl Probe"); + return; + } } - else if (candidates.size () > 1) + + if (candidates.size () > 1) { ReportMultipleCandidateError::Report (candidates, seg.get_segment (), seg.get_locus ()); -- cgit v1.1