@@ -67,6 +67,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
67
67
use errors:: DiagnosticBuilder ;
68
68
69
69
use std:: cell:: { Cell , RefCell } ;
70
+ use std:: cmp;
70
71
use std:: fmt;
71
72
use std:: mem:: replace;
72
73
use std:: rc:: Rc ;
@@ -3224,7 +3225,7 @@ fn show_candidates(session: &mut DiagnosticBuilder,
3224
3225
better : bool ) {
3225
3226
// don't show more than MAX_CANDIDATES results, so
3226
3227
// we're consistent with the trait suggestions
3227
- const MAX_CANDIDATES : usize = 5 ;
3228
+ const MAX_CANDIDATES : usize = 4 ;
3228
3229
3229
3230
// we want consistent results across executions, but candidates are produced
3230
3231
// by iterating through a hash map, so make sure they are ordered:
@@ -3237,21 +3238,21 @@ fn show_candidates(session: &mut DiagnosticBuilder,
3237
3238
1 => " is found in another module, you can import it" ,
3238
3239
_ => "s are found in other modules, you can import them" ,
3239
3240
} ;
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
+ ) ) ;
3255
3256
}
3256
3257
3257
3258
/// A somewhat inefficient routine to obtain the name of a module.
0 commit comments