Skip to content

Commit

Permalink
show list of candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
ABouttefeux committed May 25, 2021
1 parent 120691c commit 5d8e6ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
34 changes: 21 additions & 13 deletions compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/issues/issue-30123.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 12 additions & 8 deletions src/test/ui/methods/method-not-found-generic-arg-elision.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5d8e6ea

Please sign in to comment.