Skip to content

Commit

Permalink
Probe for candidates on based on the actual receiver type
Browse files Browse the repository at this point in the history
Impl blocks Self type is a TypeNoBouns which means it can be for types
such as: impl<T> &T {}.

I think we might need to change the probe algorithm for method calls to be
fully based on the autoderef rather than trying to filter based on the Self
type. More investigation is needed for the probe phase here.

Fixes #808
  • Loading branch information
philberty committed Nov 17, 2021
1 parent e8695ee commit db83283
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
22 changes: 18 additions & 4 deletions gcc/rust/typecheck/rust-hir-type-check-expr.h
Expand Up @@ -265,15 +265,29 @@ class TypeCheckExpr : public TypeCheckBase
bool probe_impls = !receiver_is_generic;
bool ignore_mandatory_trait_items = !receiver_is_generic;

auto probe_type = probe_impls ? receiver_tyty : root;
auto candidates
= PathProbeType::Probe (root, expr.get_method_name ().get_segment (),
= PathProbeType::Probe (probe_type,
expr.get_method_name ().get_segment (),
probe_impls, probe_bounds,
ignore_mandatory_trait_items);
if (candidates.empty ())
{
rust_error_at (expr.get_locus (),
"failed to resolve the PathExprSegment to any item");
return;
if (probe_impls)
{
candidates
= PathProbeType::Probe (root,
expr.get_method_name ().get_segment (),
probe_impls, probe_bounds,
ignore_mandatory_trait_items);
}

if (candidates.empty ())
{
rust_error_at (expr.get_locus (),
"failed to resolve the PathExprSegment to any item");
return;
}
}

std::vector<Adjustment> adjustments;
Expand Down
23 changes: 23 additions & 0 deletions gcc/testsuite/rust/compile/torture/issue-808.rs
@@ -0,0 +1,23 @@
pub trait Foo {
type Target;
// { dg-warning "unused name" "" { target *-*-* } .-1 }

fn bar(&self) -> &Self::Target;
// { dg-warning "unused name .self." "" { target *-*-* } .-1 }
// { dg-warning "unused name .Foo::bar." "" { target *-*-* } .-2 }
}

impl<T> Foo for &T {
type Target = T;

fn bar(&self) -> &T {
*self
}
}

pub fn main() {
let a: i32 = 123;
let b: &i32 = &a;

b.bar();
}

0 comments on commit db83283

Please sign in to comment.