aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-08-22 14:34:14 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-08-22 14:56:27 +0100
commitdb24e859d8f0141ba97d828deed7cd0d0ae9a43d (patch)
tree678ef9c4448e1b7a744a61d10bb56469229b756e /gcc
parentcbfc0ee239fafc0dadaae314138410f9119c65fa (diff)
downloadgcc-db24e859d8f0141ba97d828deed7cd0d0ae9a43d.zip
gcc-db24e859d8f0141ba97d828deed7cd0d0ae9a43d.tar.gz
gcc-db24e859d8f0141ba97d828deed7cd0d0ae9a43d.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-path.cc21
1 files changed, 15 insertions, 6 deletions
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 ());