@@ -1700,41 +1700,72 @@ crate fn show_candidates(
17001700 return ;
17011701 }
17021702
1703+ let mut accessible_path_strings: Vec < ( String , & str ) > = Vec :: new ( ) ;
1704+ let mut inaccessible_path_strings: Vec < ( String , & str ) > = Vec :: new ( ) ;
1705+
1706+ candidates. iter ( ) . for_each ( |c| {
1707+ ( if c. accessible { & mut accessible_path_strings } else { & mut inaccessible_path_strings } )
1708+ . push ( ( path_names_to_string ( & c. path ) , c. descr ) )
1709+ } ) ;
1710+
17031711 // we want consistent results across executions, but candidates are produced
17041712 // by iterating through a hash map, so make sure they are ordered:
1705- let mut path_strings: Vec < _ > =
1706- candidates. iter ( ) . map ( |c| path_names_to_string ( & c. path ) ) . collect ( ) ;
1713+ for path_strings in [ & mut accessible_path_strings, & mut inaccessible_path_strings] {
1714+ path_strings. sort ( ) ;
1715+ let core_path_strings =
1716+ path_strings. drain_filter ( |p| p. starts_with ( "core::" ) ) . collect :: < Vec < String > > ( ) ;
1717+ path_strings. extend ( core_path_strings) ;
1718+ path_strings. dedup ( ) ;
1719+ }
17071720
1708- path_strings. sort ( ) ;
1709- let core_path_strings =
1710- path_strings. drain_filter ( |p| p. starts_with ( "core::" ) ) . collect :: < Vec < String > > ( ) ;
1711- path_strings. extend ( core_path_strings) ;
1712- path_strings. dedup ( ) ;
1721+ if !accessible_path_strings. is_empty ( ) {
1722+ let ( determiner, kind) = if accessible_path_strings. len ( ) == 1 {
1723+ ( "this" , accessible_path_strings[ 0 ] . 1 )
1724+ } else {
1725+ ( "one of these" , "items" )
1726+ } ;
17131727
1714- let ( determiner, kind) = if candidates. len ( ) == 1 {
1715- ( "this" , candidates[ 0 ] . descr )
1716- } else {
1717- ( "one of these" , "items" )
1718- } ;
1719-
1720- let instead = if instead { " instead" } else { "" } ;
1721- let mut msg = format ! ( "consider importing {} {}{}" , determiner, kind, instead) ;
1722-
1723- if let Some ( span) = use_placement_span {
1724- for candidate in & mut path_strings {
1725- // produce an additional newline to separate the new use statement
1726- // from the directly following item.
1727- let additional_newline = if found_use { "" } else { "\n " } ;
1728- * candidate = format ! ( "use {};\n {}" , candidate, additional_newline) ;
1729- }
1728+ let instead = if instead { " instead" } else { "" } ;
1729+ let mut msg = format ! ( "consider importing {} {}{}" , determiner, kind, instead) ;
17301730
1731- err. span_suggestions ( span, & msg, path_strings. into_iter ( ) , Applicability :: Unspecified ) ;
1731+ if let Some ( span) = use_placement_span {
1732+ for candidate in & mut accessible_path_strings {
1733+ // produce an additional newline to separate the new use statement
1734+ // from the directly following item.
1735+ let additional_newline = if found_use { "" } else { "\n " } ;
1736+ candidate. 0 = format ! ( "use {};\n {}" , & candidate. 0 , additional_newline) ;
1737+ }
1738+
1739+ err. span_suggestions (
1740+ span,
1741+ & msg,
1742+ accessible_path_strings. into_iter ( ) . map ( |a| a. 0 ) ,
1743+ Applicability :: Unspecified ,
1744+ ) ;
1745+ } else {
1746+ msg. push ( ':' ) ;
1747+
1748+ for candidate in accessible_path_strings {
1749+ msg. push ( '\n' ) ;
1750+ msg. push_str ( & candidate. 0 ) ;
1751+ }
1752+
1753+ err. note ( & msg) ;
1754+ }
17321755 } else {
1733- msg. push ( ':' ) ;
1756+ assert ! ( !inaccessible_path_strings. is_empty( ) ) ;
1757+
1758+ let ( determiner, kind, verb1, verb2) = if inaccessible_path_strings. len ( ) == 1 {
1759+ ( "this" , inaccessible_path_strings[ 0 ] . 1 , "exists" , "is" )
1760+ } else {
1761+ ( "these" , "items" , "exist" , "are" )
1762+ } ;
1763+
1764+ let mut msg = format ! ( "{} {} {} but {} inaccessible:" , determiner, kind, verb1, verb2) ;
17341765
1735- for candidate in path_strings {
1766+ for candidate in inaccessible_path_strings {
17361767 msg. push ( '\n' ) ;
1737- msg. push_str ( & candidate) ;
1768+ msg. push_str ( & candidate. 0 ) ;
17381769 }
17391770
17401771 err. note ( & msg) ;
0 commit comments