@@ -101,8 +101,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
101
101
102
102
sources. sort ( ) ;
103
103
sources. dedup ( ) ;
104
+ // Dynamic limit to avoid hiding just one candidate, which is silly.
105
+ let limit = if sources. len ( ) == 5 { 5 } else { 4 } ;
104
106
105
- for ( idx, source) in sources. iter ( ) . enumerate ( ) {
107
+ for ( idx, source) in sources. iter ( ) . take ( limit ) . enumerate ( ) {
106
108
match * source {
107
109
CandidateSource :: ImplSource ( impl_did) => {
108
110
// Provide the best span we can. Use the item, if local to crate, else
@@ -151,6 +153,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
151
153
}
152
154
}
153
155
}
156
+ if sources. len ( ) > limit {
157
+ err. note ( & format ! ( "and {} others" , sources. len( ) - limit) ) ;
158
+ }
154
159
} ;
155
160
156
161
match error {
@@ -295,11 +300,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
295
300
296
301
err. help ( & msg[ ..] ) ;
297
302
298
- for ( i, trait_did) in candidates. iter ( ) . enumerate ( ) {
303
+ let limit = if candidates. len ( ) == 5 { 5 } else { 4 } ;
304
+ for ( i, trait_did) in candidates. iter ( ) . take ( limit) . enumerate ( ) {
299
305
err. help ( & format ! ( "candidate #{}: `use {}`" ,
300
306
i + 1 ,
301
307
self . tcx. item_path_str( * trait_did) ) ) ;
302
308
}
309
+ if candidates. len ( ) > limit {
310
+ err. note ( & format ! ( "and {} others" , candidates. len( ) - limit) ) ;
311
+ }
303
312
return
304
313
}
305
314
0 commit comments