diff options
| author | AliƩnore Bouttefeux <alienore.bouttefeux@gmail.com> | 2021-05-25 16:55:30 +0200 |
|---|---|---|
| committer | AliƩnore Bouttefeux <alienore.bouttefeux@gmail.com> | 2021-05-25 16:55:30 +0200 |
| commit | 5d8e6ea7b9e668578917940d2ab1ba1a51b291b5 (patch) | |
| tree | a9572b0983195350624886bd491436d087a0013d | |
| parent | 120691c590c4309fda31994931b9a561b4249c33 (diff) | |
show list of candidates
| -rw-r--r-- | compiler/rustc_typeck/src/check/method/suggest.rs | 34 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-30123.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/methods/method-not-found-generic-arg-elision.stderr | 20 |
3 files changed, 35 insertions, 22 deletions
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::<Vec<_>>(); - // 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::<Vec<_>>() + .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::<i32, i32>::new_undirected(); | ^^^^^^^^^^^^^^ function or associated item not found in `issue_30123_aux::Graph<i32, i32>` | - = note: the function or associated item was found for issue_30123_aux::Graph<N, E, Undirected> + = note: the function or associated item was found for + - `issue_30123_aux::Graph<N, E, Undirected>` 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<T> { LL | let d = point_i32.distance(); | ^^^^^^^^ method not found in `Point<i32>` | - = note: the method was found for Point<f64> + = note: the method was found for + - `Point<f64>` 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>(T); LL | wrapper.method(); | ^^^^^^ method not found in `Wrapper<bool>` | - = note: the method was found for Wrapper<i8> - = note: the method was found for Wrapper<i16> - = note: the method was found for Wrapper<i32> - = note: the method was found for 3 more types + = note: the method was found for + - `Wrapper<i8>` + - `Wrapper<i16>` + - `Wrapper<i32>` + - `Wrapper<i64>` + 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 |
