@@ -67,6 +67,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
6767use errors:: DiagnosticBuilder ;
6868
6969use std:: cell:: { Cell , RefCell } ;
70+ use std:: cmp;
7071use std:: fmt;
7172use std:: mem:: replace;
7273use std:: rc:: Rc ;
@@ -3224,7 +3225,7 @@ fn show_candidates(session: &mut DiagnosticBuilder,
32243225 better : bool ) {
32253226 // don't show more than MAX_CANDIDATES results, so
32263227 // we're consistent with the trait suggestions
3227- const MAX_CANDIDATES : usize = 5 ;
3228+ const MAX_CANDIDATES : usize = 4 ;
32283229
32293230 // we want consistent results across executions, but candidates are produced
32303231 // by iterating through a hash map, so make sure they are ordered:
@@ -3237,21 +3238,21 @@ fn show_candidates(session: &mut DiagnosticBuilder,
32373238 1 => " is found in another module, you can import it" ,
32383239 _ => "s are found in other modules, you can import them" ,
32393240 } ;
3240- session . help ( & format ! ( "possible {}candidate{} into scope:" , better , msg_diff ) ) ;
3241-
3242- let count = path_strings . len ( ) as isize - MAX_CANDIDATES as isize + 1 ;
3243- for ( idx , path_string ) in path_strings . iter ( ) . enumerate ( ) {
3244- if idx == MAX_CANDIDATES - 1 && count > 1 {
3245- session . help (
3246- & format ! ( " and {} other candidates " , count ) . to_string ( ) ,
3247- ) ;
3248- break ;
3249- } else {
3250- session . help (
3251- & format ! ( " `use {};`" , path_string ) . to_string ( ) ,
3252- ) ;
3253- }
3254- }
3241+
3242+ let end = cmp :: min ( MAX_CANDIDATES , path_strings . len ( ) ) ;
3243+ session . help ( & format ! ( "possible {}candidate{} into scope:{}{}" ,
3244+ better ,
3245+ msg_diff ,
3246+ & path_strings [ 0 ..end ] . iter ( ) . map ( |candidate| {
3247+ format!( "\n `use {};` " , candidate )
3248+ } ) . collect :: < String > ( ) ,
3249+ if path_strings . len ( ) > MAX_CANDIDATES {
3250+ format! ( " \n and {} other candidates" ,
3251+ path_strings . len ( ) - MAX_CANDIDATES )
3252+ } else {
3253+ "" . to_owned ( )
3254+ }
3255+ ) ) ;
32553256}
32563257
32573258/// A somewhat inefficient routine to obtain the name of a module.
0 commit comments