@@ -47,6 +47,7 @@ impl TypoSuggestion {
4747/// A free importable items suggested in case of resolution failure.
4848crate struct ImportSuggestion {
4949 pub did : Option < DefId > ,
50+ pub descr : & ' static str ,
5051 pub path : Path ,
5152}
5253
@@ -652,7 +653,7 @@ impl<'a> Resolver<'a> {
652653 Res :: Def ( DefKind :: Ctor ( ..) , did) => this. parent ( did) ,
653654 _ => res. opt_def_id ( ) ,
654655 } ;
655- candidates. push ( ImportSuggestion { did, path } ) ;
656+ candidates. push ( ImportSuggestion { did, descr : res . descr ( ) , path } ) ;
656657 }
657658 }
658659 }
@@ -1445,29 +1446,31 @@ fn find_span_immediately_after_crate_name(
14451446crate fn show_candidates (
14461447 err : & mut DiagnosticBuilder < ' _ > ,
14471448 // This is `None` if all placement locations are inside expansions
1448- span : Option < Span > ,
1449+ use_placement_span : Option < Span > ,
14491450 candidates : & [ ImportSuggestion ] ,
14501451 better : bool ,
14511452 found_use : bool ,
14521453) {
14531454 if candidates. is_empty ( ) {
14541455 return ;
14551456 }
1457+
14561458 // we want consistent results across executions, but candidates are produced
14571459 // by iterating through a hash map, so make sure they are ordered:
14581460 let mut path_strings: Vec < _ > =
14591461 candidates. iter ( ) . map ( |c| path_names_to_string ( & c. path ) ) . collect ( ) ;
14601462 path_strings. sort ( ) ;
14611463 path_strings. dedup ( ) ;
14621464
1463- let better = if better { "better " } else { "" } ;
1464- let msg_diff = match path_strings . len ( ) {
1465- 1 => " is found in another module, you can import it" ,
1466- _ => "s are found in other modules, you can import them" ,
1465+ let ( determiner , kind ) = if candidates . len ( ) == 1 {
1466+ ( "this" , candidates [ 0 ] . descr )
1467+ } else {
1468+ ( "one of these" , "items" )
14671469 } ;
1468- let msg = format ! ( "possible {}candidate{} into scope" , better, msg_diff) ;
1470+ let instead = if better { " instead" } else { "" } ;
1471+ let msg = format ! ( "consider importing {} {}{}" , determiner, kind, instead) ;
14691472
1470- if let Some ( span) = span {
1473+ if let Some ( span) = use_placement_span {
14711474 for candidate in & mut path_strings {
14721475 // produce an additional newline to separate the new use statement
14731476 // from the directly following item.
0 commit comments