@@ -101,8 +101,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
101101
102102 sources. sort ( ) ;
103103 sources. dedup ( ) ;
104+ // Dynamic limit to avoid hiding just one candidate, which is silly.
105+ let limit = if sources. len ( ) == 5 { 5 } else { 4 } ;
104106
105- for ( idx, source) in sources. iter ( ) . enumerate ( ) {
107+ for ( idx, source) in sources. iter ( ) . take ( limit ) . enumerate ( ) {
106108 match * source {
107109 CandidateSource :: ImplSource ( impl_did) => {
108110 // 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> {
151153 }
152154 }
153155 }
156+ if sources. len ( ) > limit {
157+ err. note ( & format ! ( "and {} others" , sources. len( ) - limit) ) ;
158+ }
154159 } ;
155160
156161 match error {
@@ -295,11 +300,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
295300
296301 err. help ( & msg[ ..] ) ;
297302
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 ( ) {
299305 err. help ( & format ! ( "candidate #{}: `use {}`" ,
300306 i + 1 ,
301307 self . tcx. item_path_str( * trait_did) ) ) ;
302308 }
309+ if candidates. len ( ) > limit {
310+ err. note ( & format ! ( "and {} others" , candidates. len( ) - limit) ) ;
311+ }
303312 return
304313 }
305314
0 commit comments