show list of candidates

This commit is contained in:
Aliénore Bouttefeux 2021-05-25 16:55:30 +02:00
parent 120691c590
commit 5d8e6ea7b9
3 changed files with 35 additions and 22 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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