Do not call name() on rpitit assoc_item
(cherry picked from commit 66d47c1687)
This commit is contained in:
parent
542e61c21b
commit
14acce0cb6
3 changed files with 47 additions and 10 deletions
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
tests/ui/impl-trait/in-trait/not-inferred-generic.rs
Normal file
13
tests/ui/impl-trait/in-trait/not-inferred-generic.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
trait TypedClient {
|
||||
fn publish_typed<F>(&self) -> impl Sized
|
||||
where
|
||||
F: Clone;
|
||||
}
|
||||
impl TypedClient for () {
|
||||
fn publish_typed<F>(&self) -> impl Sized {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
().publish_typed();
|
||||
//~^ ERROR type annotations needed [E0283]
|
||||
}
|
||||
21
tests/ui/impl-trait/in-trait/not-inferred-generic.stderr
Normal file
21
tests/ui/impl-trait/in-trait/not-inferred-generic.stderr
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue