Skip to content

Do not call name() on rpitit assoc_item #141308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ known-bug: #141143
trait TypedClient {
fn publish_typed<F>(&self) -> impl Sized
where
Expand All @@ -10,4 +9,5 @@ impl TypedClient for () {

fn main() {
().publish_typed();
//~^ ERROR type annotations needed [E0283]
}
21 changes: 21 additions & 0 deletions tests/ui/impl-trait/in-trait/not-inferred-generic.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading