Do not call name() on rpitit assoc_item · Amanieu/rust@66d47c1 (original) (raw)

File tree

3 files changed

lines changed

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -2124,16 +2124,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
2124 2124 accessed through a specific `impl`",
2125 2125 self.tcx.def_kind_descr(assoc_item.as_def_kind(), item_def_id)
2126 2126 ));
2127 - err.span_suggestion(
2128 - span,
2129 -"use the fully qualified path to an implementation",
2130 -format!(
2131 -"<Type as {}>::{}",
2132 -self.tcx.def_path_str(trait_ref),
2133 - assoc_item.name()
2134 -),
2135 -Applicability::HasPlaceholders,
2136 -);
2127 +
2128 +if !assoc_item.is_impl_trait_in_trait() {
2129 + err.span_suggestion(
2130 + span,
2131 +"use the fully qualified path to an implementation",
2132 +format!(
2133 +"<Type as {}>::{}",
2134 +self.tcx.def_path_str(trait_ref),
2135 + assoc_item.name()
2136 +),
2137 +Applicability::HasPlaceholders,
2138 +);
2139 +}
2137 2140 }
2138 2141 }
2139 2142 }
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
1 -//@ known-bug: #141143
2 1 trait TypedClient {
3 2 fn publish_typed<F>(&self) -> impl Sized
4 3 where
@@ -10,4 +9,5 @@ impl TypedClient for () {
10 9
11 10 fn main() {
12 11 ().publish_typed();
12 +//~^ ERROR type annotations needed [E0283]
13 13 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1 +error[E0283]: type annotations needed
2 + --> $DIR/not-inferred-generic.rs:11:8
3 + |
4 +LL | ().publish_typed();
5 + | ^^^^^^^^^^^^^ cannot infer type of the type parameter `F` declared on the method `publish_typed`
6 + |
7 + = note: cannot satisfy `_: Clone`
8 + = note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
9 +note: required by a bound in `TypedClient::publish_typed::{anon_assoc#0}`
10 + --> $DIR/not-inferred-generic.rs:4:12
11 + |
12 +LL | F: Clone;
13 + | ^^^^^ required by this bound in `TypedClient::publish_typed::{anon_assoc#0}`
14 +help: consider specifying the generic argument
15 + |
16 +LL | ().publish_typed::();
17 + | +++++
18 +
19 +error: aborting due to 1 previous error
20 +
21 +For more information about this error, try `rustc --explain E0283`.