about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-14 11:27:12 +0200
committerGitHub <noreply@github.com>2025-06-14 11:27:12 +0200
commit4bf7765388da436dc952ac7300ffc114cff37676 (patch)
tree4e15c4c8b4edb689fc58cadc722af98fa0a52202 /tests
parentfe54c3a5eba611dd9b7f875931f484a7ceef4df2 (diff)
parent1d036f408efa6e12b2fcd35588b4595fde5b0af2 (diff)
downloadrust-4bf7765388da436dc952ac7300ffc114cff37676.tar.gz
rust-4bf7765388da436dc952ac7300ffc114cff37676.zip
Rollup merge of #142477 - JonathanBrouwer:associated-type-suggestion, r=WaffleLapkin
Fix incorrect suggestion when calling an associated type with a type anchor

`sugg_span` here is the span of the call expression.
That span here is the `<Self>::Assoc`, which is exactly what we need here (even though I would expect it to include the arguments, but I guess it doesn't)

r? ``@WaffleLapkin``
One commit with failing tests and one that fixes it for reviewability

closes rust-lang/rust#142473
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/associated-types/associated-type-call.fixed22
-rw-r--r--tests/ui/associated-types/associated-type-call.rs22
-rw-r--r--tests/ui/associated-types/associated-type-call.stderr15
3 files changed, 59 insertions, 0 deletions
diff --git a/tests/ui/associated-types/associated-type-call.fixed b/tests/ui/associated-types/associated-type-call.fixed
new file mode 100644
index 00000000000..d450b3b82c9
--- /dev/null
+++ b/tests/ui/associated-types/associated-type-call.fixed
@@ -0,0 +1,22 @@
+// issue: <https://github.com/rust-lang/rust/issues/142473>
+//
+//@ run-rustfix
+#![allow(unused)]
+struct T();
+
+trait Trait {
+    type Assoc;
+
+    fn f();
+}
+
+impl Trait for () {
+    type Assoc = T;
+
+    fn f() {
+        T();
+        //~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/associated-types/associated-type-call.rs b/tests/ui/associated-types/associated-type-call.rs
new file mode 100644
index 00000000000..ffe540c329e
--- /dev/null
+++ b/tests/ui/associated-types/associated-type-call.rs
@@ -0,0 +1,22 @@
+// issue: <https://github.com/rust-lang/rust/issues/142473>
+//
+//@ run-rustfix
+#![allow(unused)]
+struct T();
+
+trait Trait {
+    type Assoc;
+
+    fn f();
+}
+
+impl Trait for () {
+    type Assoc = T;
+
+    fn f() {
+        <Self>::Assoc();
+        //~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/associated-types/associated-type-call.stderr b/tests/ui/associated-types/associated-type-call.stderr
new file mode 100644
index 00000000000..eaef775e304
--- /dev/null
+++ b/tests/ui/associated-types/associated-type-call.stderr
@@ -0,0 +1,15 @@
+error[E0599]: no associated item named `Assoc` found for unit type `()` in the current scope
+  --> $DIR/associated-type-call.rs:17:17
+   |
+LL |         <Self>::Assoc();
+   |                 ^^^^^ associated item not found in `()`
+   |
+help: to construct a value of type `T`, use the explicit path
+   |
+LL -         <Self>::Assoc();
+LL +         T();
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0599`.