public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Probe for candidates on based on the actual receiver type
@ 2022-06-08 11:52 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:db832831ed15ad25aec99a7d4a87b7019e5f1aa4

commit db832831ed15ad25aec99a7d4a87b7019e5f1aa4
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Wed Nov 17 17:38:41 2021 +0000

    Probe for candidates on based on the actual receiver type
    
    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

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.h   | 22 ++++++++++++++++++----
 gcc/testsuite/rust/compile/torture/issue-808.rs | 23 +++++++++++++++++++++++
 2 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index d5d12b4db4d..c20659229f6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -265,15 +265,29 @@ public:
     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;
diff --git a/gcc/testsuite/rust/compile/torture/issue-808.rs b/gcc/testsuite/rust/compile/torture/issue-808.rs
new file mode 100644
index 00000000000..bfbf774fd05
--- /dev/null
+++ b/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();
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 11:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 11:52 [gcc/devel/rust/master] Probe for candidates on based on the actual receiver type Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).