Skip to content

Commit 66d47c1

Browse files
committed
Do not call name() on rpitit assoc_item
1 parent 6cab15c commit 66d47c1

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,16 +2124,19 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21242124
accessed through a specific `impl`",
21252125
self.tcx.def_kind_descr(assoc_item.as_def_kind(), item_def_id)
21262126
));
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+
}
21372140
}
21382141
}
21392142
}

tests/crashes/141143.rs renamed to tests/ui/impl-trait/in-trait/not-inferred-generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ known-bug: #141143
21
trait TypedClient {
32
fn publish_typed<F>(&self) -> impl Sized
43
where
@@ -10,4 +9,5 @@ impl TypedClient for () {
109

1110
fn main() {
1211
().publish_typed();
12+
//~^ ERROR type annotations needed [E0283]
1313
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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::<F>();
17+
| +++++
18+
19+
error: aborting due to 1 previous error
20+
21+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)