Skip to content

Commit 44042cc

Browse files
committed
fix: apply review feedbacks
1 parent 8738862 commit 44042cc

3 files changed

Lines changed: 13 additions & 22 deletions

File tree

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,11 +1065,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10651065
for (predicate, _parent_pred, _cause) in unsatisfied_predicates {
10661066
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) =
10671067
predicate.kind().skip_binder()
1068+
&& let self_ty = pred.trait_ref.self_ty()
1069+
&& self_ty.peel_refs() == rcvr_ty
10681070
{
1069-
let self_ty = pred.trait_ref.self_ty();
1070-
if self_ty.peel_refs() != rcvr_ty {
1071-
continue;
1072-
}
10731071
let is_ref = matches!(self_ty.kind(), ty::Ref(..));
10741072
tracker.track(pred.trait_ref.def_id, is_ref);
10751073
}
@@ -1102,19 +1100,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11021100
let is_ty_span = Some(span) == ty_span;
11031101
if is_ty_span && should_condense {
11041102
ty_span.take();
1105-
err.span_label(
1106-
span,
1103+
let label = if let Some(missing_trait_list) = &missing_trait_list {
1104+
format!(
1105+
"{item_kind} `{item_ident}` not found for this {} because `{rcvr_ty_str}` doesn't implement {missing_trait_list}",
1106+
rcvr_ty.prefix_string(self.tcx)
1107+
)
1108+
} else {
11071109
format!(
11081110
"{item_kind} `{item_ident}` not found for this {}",
11091111
rcvr_ty.prefix_string(self.tcx)
1110-
),
1111-
);
1112-
if let Some(missing_trait_list) = &missing_trait_list {
1113-
err.span_label(
1114-
span,
1115-
format!("`{rcvr_ty_str}` doesn't implement {missing_trait_list}"),
1116-
);
1117-
}
1112+
)
1113+
};
1114+
err.span_label(span, label);
11181115
continue;
11191116
}
11201117
let pre = if is_ty_span {

tests/ui/proc-macro/quote/not-repeatable.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0599]: the method `quote_into_iter` exists for struct `Ipv4Addr`, but its
22
--> $DIR/not-repeatable.rs:11:13
33
|
44
LL | struct Ipv4Addr;
5-
| ---------------
6-
| |
7-
| method `quote_into_iter` not found for this struct
8-
| `Ipv4Addr` doesn't implement `Iterator` or `ToTokens`
5+
| --------------- method `quote_into_iter` not found for this struct because `Ipv4Addr` doesn't implement `Iterator` or `ToTokens`
96
...
107
LL | let _ = quote! { $($ip)* };
118
| ^^^^^^^^^^^^^^^^^^ method cannot be called on `Ipv4Addr` due to unsatisfied trait bounds

tests/ui/traits/associated-item-unsatisfied-trait-bounds.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0599]: the function or associated item `bat` exists for struct `Foo`, but
22
--> $DIR/associated-item-unsatisfied-trait-bounds.rs:8:10
33
|
44
LL | struct Foo;
5-
| ----------
6-
| |
7-
| function or associated item `bat` not found for this struct
8-
| `Foo` doesn't implement `Bar` or `Baz`
5+
| ---------- function or associated item `bat` not found for this struct because `Foo` doesn't implement `Bar` or `Baz`
96
...
107
LL | Foo::bat(());
118
| ^^^ function or associated item cannot be called on `Foo` due to unsatisfied trait bounds

0 commit comments

Comments
 (0)