diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 109cd3e4bc8..569e8719227 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -517,21 +517,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if inherent_impls_candidate.len() > 0 { inherent_impls_candidate.sort(); inherent_impls_candidate.dedup(); + + // number of type to shows at most. + let limit = if inherent_impls_candidate.len() == 5 { 5 } else { 4 }; let type_candidates = inherent_impls_candidate .iter() - .map(|impl_item| self.tcx.at(span).type_of(*impl_item)) - .collect::>(); - // number of type to shows at most. - let limit = if type_candidates.len() == 4 { 4 } else { 3 }; - for ty in type_candidates.iter().take(limit) { - err.note(&format!("the {item_kind} was found for {}", ty)); - } - if type_candidates.len() > limit { - err.note(&format!( - "the {item_kind} was found for {} more types", - type_candidates.len() - limit - )); - } + .take(limit) + .map(|impl_item| { + format!("- `{}`", self.tcx.at(span).type_of(*impl_item)) + }) + .collect::>() + .join("\n"); + let additional_types = if inherent_impls_candidate.len() > limit { + format!( + "\nand {} more types", + inherent_impls_candidate.len() - limit + ) + } else { + "".to_string() + }; + err.note(&format!( + "the {item_kind} was found for\n{}{}", + type_candidates, additional_types + )); } } } else { diff --git a/src/test/ui/issues/issue-30123.stderr b/src/test/ui/issues/issue-30123.stderr index 76a6b447ac1..e9d934332f1 100644 --- a/src/test/ui/issues/issue-30123.stderr +++ b/src/test/ui/issues/issue-30123.stderr @@ -4,7 +4,8 @@ error[E0599]: no function or associated item named `new_undirected` found for st LL | let ug = Graph::::new_undirected(); | ^^^^^^^^^^^^^^ function or associated item not found in `issue_30123_aux::Graph` | - = note: the function or associated item was found for issue_30123_aux::Graph + = note: the function or associated item was found for + - `issue_30123_aux::Graph` error: aborting due to previous error diff --git a/src/test/ui/methods/method-not-found-generic-arg-elision.stderr b/src/test/ui/methods/method-not-found-generic-arg-elision.stderr index 4a9cfb4fc80..1671e5e5e64 100644 --- a/src/test/ui/methods/method-not-found-generic-arg-elision.stderr +++ b/src/test/ui/methods/method-not-found-generic-arg-elision.stderr @@ -7,7 +7,8 @@ LL | struct Point { LL | let d = point_i32.distance(); | ^^^^^^^^ method not found in `Point` | - = note: the method was found for Point + = note: the method was found for + - `Point` error[E0599]: no method named `other` found for struct `Point` in the current scope --> $DIR/method-not-found-generic-arg-elision.rs:84:23 @@ -33,10 +34,12 @@ LL | struct Wrapper(T); LL | wrapper.method(); | ^^^^^^ method not found in `Wrapper` | - = note: the method was found for Wrapper - = note: the method was found for Wrapper - = note: the method was found for Wrapper - = note: the method was found for 3 more types + = note: the method was found for + - `Wrapper` + - `Wrapper` + - `Wrapper` + - `Wrapper` + and 2 more types error[E0599]: no method named `other` found for struct `Wrapper` in the current scope --> $DIR/method-not-found-generic-arg-elision.rs:92:13 @@ -56,9 +59,10 @@ LL | struct Wrapper2<'a, T, const C: usize> { LL | wrapper.method(); | ^^^^^^ method not found in `Wrapper2<'_, bool, 3_usize>` | - = note: the method was found for Wrapper2<'a, i8, C> - = note: the method was found for Wrapper2<'a, i16, C> - = note: the method was found for Wrapper2<'a, i32, C> + = note: the method was found for + - `Wrapper2<'a, i8, C>` + - `Wrapper2<'a, i16, C>` + - `Wrapper2<'a, i32, C>` error[E0599]: no method named `other` found for struct `Wrapper2` in the current scope --> $DIR/method-not-found-generic-arg-elision.rs:98:13