Skip to content

Commit 5d8e6ea

Browse files
committed
show list of candidates
1 parent 120691c commit 5d8e6ea

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

compiler/rustc_typeck/src/check/method/suggest.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -517,21 +517,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517517
if inherent_impls_candidate.len() > 0 {
518518
inherent_impls_candidate.sort();
519519
inherent_impls_candidate.dedup();
520+
521+
// number of type to shows at most.
522+
let limit = if inherent_impls_candidate.len() == 5 { 5 } else { 4 };
520523
let type_candidates = inherent_impls_candidate
521524
.iter()
522-
.map(|impl_item| self.tcx.at(span).type_of(*impl_item))
523-
.collect::<Vec<_>>();
524-
// number of type to shows at most.
525-
let limit = if type_candidates.len() == 4 { 4 } else { 3 };
526-
for ty in type_candidates.iter().take(limit) {
527-
err.note(&format!("the {item_kind} was found for {}", ty));
528-
}
529-
if type_candidates.len() > limit {
530-
err.note(&format!(
531-
"the {item_kind} was found for {} more types",
532-
type_candidates.len() - limit
533-
));
534-
}
525+
.take(limit)
526+
.map(|impl_item| {
527+
format!("- `{}`", self.tcx.at(span).type_of(*impl_item))
528+
})
529+
.collect::<Vec<_>>()
530+
.join("\n");
531+
let additional_types = if inherent_impls_candidate.len() > limit {
532+
format!(
533+
"\nand {} more types",
534+
inherent_impls_candidate.len() - limit
535+
)
536+
} else {
537+
"".to_string()
538+
};
539+
err.note(&format!(
540+
"the {item_kind} was found for\n{}{}",
541+
type_candidates, additional_types
542+
));
535543
}
536544
}
537545
} else {

src/test/ui/issues/issue-30123.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error[E0599]: no function or associated item named `new_undirected` found for st
44
LL | let ug = Graph::<i32, i32>::new_undirected();
55
| ^^^^^^^^^^^^^^ function or associated item not found in `issue_30123_aux::Graph<i32, i32>`
66
|
7-
= note: the function or associated item was found for issue_30123_aux::Graph<N, E, Undirected>
7+
= note: the function or associated item was found for
8+
- `issue_30123_aux::Graph<N, E, Undirected>`
89

910
error: aborting due to previous error
1011

src/test/ui/methods/method-not-found-generic-arg-elision.stderr

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ LL | struct Point<T> {
77
LL | let d = point_i32.distance();
88
| ^^^^^^^^ method not found in `Point<i32>`
99
|
10-
= note: the method was found for Point<f64>
10+
= note: the method was found for
11+
- `Point<f64>`
1112

1213
error[E0599]: no method named `other` found for struct `Point` in the current scope
1314
--> $DIR/method-not-found-generic-arg-elision.rs:84:23
@@ -33,10 +34,12 @@ LL | struct Wrapper<T>(T);
3334
LL | wrapper.method();
3435
| ^^^^^^ method not found in `Wrapper<bool>`
3536
|
36-
= note: the method was found for Wrapper<i8>
37-
= note: the method was found for Wrapper<i16>
38-
= note: the method was found for Wrapper<i32>
39-
= note: the method was found for 3 more types
37+
= note: the method was found for
38+
- `Wrapper<i8>`
39+
- `Wrapper<i16>`
40+
- `Wrapper<i32>`
41+
- `Wrapper<i64>`
42+
and 2 more types
4043

4144
error[E0599]: no method named `other` found for struct `Wrapper` in the current scope
4245
--> $DIR/method-not-found-generic-arg-elision.rs:92:13
@@ -56,9 +59,10 @@ LL | struct Wrapper2<'a, T, const C: usize> {
5659
LL | wrapper.method();
5760
| ^^^^^^ method not found in `Wrapper2<'_, bool, 3_usize>`
5861
|
59-
= note: the method was found for Wrapper2<'a, i8, C>
60-
= note: the method was found for Wrapper2<'a, i16, C>
61-
= note: the method was found for Wrapper2<'a, i32, C>
62+
= note: the method was found for
63+
- `Wrapper2<'a, i8, C>`
64+
- `Wrapper2<'a, i16, C>`
65+
- `Wrapper2<'a, i32, C>`
6266

6367
error[E0599]: no method named `other` found for struct `Wrapper2` in the current scope
6468
--> $DIR/method-not-found-generic-arg-elision.rs:98:13

0 commit comments

Comments
 (0)