about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs23
-rw-r--r--tests/ui/impl-trait/in-trait/not-inferred-generic.rs (renamed from tests/crashes/141143.rs)2
-rw-r--r--tests/ui/impl-trait/in-trait/not-inferred-generic.stderr21
3 files changed, 35 insertions, 11 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
index 8801397b775..6863857f9ec 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
@@ -2124,16 +2124,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
                         accessed through a specific `impl`",
                     self.tcx.def_kind_descr(assoc_item.as_def_kind(), item_def_id)
                 ));
-                err.span_suggestion(
-                    span,
-                    "use the fully qualified path to an implementation",
-                    format!(
-                        "<Type as {}>::{}",
-                        self.tcx.def_path_str(trait_ref),
-                        assoc_item.name()
-                    ),
-                    Applicability::HasPlaceholders,
-                );
+
+                if !assoc_item.is_impl_trait_in_trait() {
+                    err.span_suggestion(
+                        span,
+                        "use the fully qualified path to an implementation",
+                        format!(
+                            "<Type as {}>::{}",
+                            self.tcx.def_path_str(trait_ref),
+                            assoc_item.name()
+                        ),
+                        Applicability::HasPlaceholders,
+                    );
+                }
             }
         }
     }
diff --git a/tests/crashes/141143.rs b/tests/ui/impl-trait/in-trait/not-inferred-generic.rs
index a4aa2f19a6c..3879ea0e626 100644
--- a/tests/crashes/141143.rs
+++ b/tests/ui/impl-trait/in-trait/not-inferred-generic.rs
@@ -1,4 +1,3 @@
-//@ known-bug: #141143
 trait TypedClient {
     fn publish_typed<F>(&self) -> impl Sized
     where
@@ -10,4 +9,5 @@ impl TypedClient for () {
 
 fn main() {
     ().publish_typed();
+    //~^ ERROR type annotations needed [E0283]
 }
diff --git a/tests/ui/impl-trait/in-trait/not-inferred-generic.stderr b/tests/ui/impl-trait/in-trait/not-inferred-generic.stderr
new file mode 100644
index 00000000000..07f029d3bb7
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/not-inferred-generic.stderr
@@ -0,0 +1,21 @@
+error[E0283]: type annotations needed
+  --> $DIR/not-inferred-generic.rs:11:8
+   |
+LL |     ().publish_typed();
+   |        ^^^^^^^^^^^^^ cannot infer type of the type parameter `F` declared on the method `publish_typed`
+   |
+   = note: cannot satisfy `_: Clone`
+   = note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
+note: required by a bound in `TypedClient::publish_typed::{anon_assoc#0}`
+  --> $DIR/not-inferred-generic.rs:4:12
+   |
+LL |         F: Clone;
+   |            ^^^^^ required by this bound in `TypedClient::publish_typed::{anon_assoc#0}`
+help: consider specifying the generic argument
+   |
+LL |     ().publish_typed::<F>();
+   |                     +++++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0283`.