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 2825241
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-expr.h
Expand Up @@ -265,8 +265,10 @@ 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 ())
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 2825241

Please sign in to comment.