aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-11-17 17:38:41 +0000
committerPhilip Herron <philip.herron@embecosm.com>2021-11-17 19:44:58 +0000
commitdb832831ed15ad25aec99a7d4a87b7019e5f1aa4 (patch)
tree3efc2aa5786eed2f58dd506c7de1cc9b72354cbd /gcc
parente8695eee4f1b9121d0caa7a93ff51f69707c607f (diff)
downloadgcc-db832831ed15ad25aec99a7d4a87b7019e5f1aa4.zip
gcc-db832831ed15ad25aec99a7d4a87b7019e5f1aa4.tar.gz
gcc-db832831ed15ad25aec99a7d4a87b7019e5f1aa4.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.h22
-rw-r--r--gcc/testsuite/rust/compile/torture/issue-808.rs23
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 d5d12b4..c206592 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 0000000..bfbf774
--- /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();
+}