From 66d47c16873fc04a02cb0bd977ec7f3d50f228f1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 20 May 2025 16:55:09 -0300 Subject: [PATCH] Do not call name() on rpitit assoc_item --- .../src/error_reporting/traits/suggestions.rs | 23 +++++++++++-------- .../in-trait/not-inferred-generic.rs} | 2 +- .../in-trait/not-inferred-generic.stderr | 21 +++++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) rename tests/{crashes/141143.rs => ui/impl-trait/in-trait/not-inferred-generic.rs} (81%) create mode 100644 tests/ui/impl-trait/in-trait/not-inferred-generic.stderr 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 8801397b77541..6863857f9ecb8 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!( - "::{}", - 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!( + "::{}", + 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 similarity index 81% rename from tests/crashes/141143.rs rename to tests/ui/impl-trait/in-trait/not-inferred-generic.rs index a4aa2f19a6c75..3879ea0e62628 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(&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 0000000000000..07f029d3bb7dc --- /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::(); + | +++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`.