@@ -1325,9 +1325,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13251325 } )
13261326 }
13271327
1328- // If only some candidates are accessible, take just them
1328+ // If only some candidates are accessible, add note to make it public
13291329 if !candidates. iter ( ) . all ( |v : & ImportSuggestion | !v. accessible ) {
1330- candidates. retain ( |x| x. accessible )
1330+ candidates. iter_mut ( ) . for_each ( |v| {
1331+ if !v. accessible {
1332+ v. note = Some ( format ! (
1333+ "maybe you should make the path `{}` public with `pub`" ,
1334+ path_names_to_string( & v. path)
1335+ ) ) ;
1336+ }
1337+ } ) ;
13311338 }
13321339
13331340 candidates
@@ -1794,7 +1801,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17941801 & import_suggestions,
17951802 Instead :: Yes ,
17961803 FoundUse :: Yes ,
1797- DiagMode :: Import { append : single_nested } ,
1804+ DiagMode :: Import { append : single_nested, unresolved_import : false } ,
17981805 vec ! [ ] ,
17991806 "" ,
18001807 ) ;
@@ -2751,6 +2758,8 @@ pub(crate) enum DiagMode {
27512758 Pattern ,
27522759 /// The binding is part of a use statement
27532760 Import {
2761+ /// `true` means diagnostics is for unresolved import
2762+ unresolved_import : bool ,
27542763 /// `true` mean add the tips afterward for case `use a::{b,c}`,
27552764 /// rather than replacing within.
27562765 append : bool ,
@@ -2801,6 +2810,7 @@ fn show_candidates(
28012810 return false ;
28022811 }
28032812
2813+ let mut showed = false ;
28042814 let mut accessible_path_strings: Vec < PathString < ' _ > > = Vec :: new ( ) ;
28052815 let mut inaccessible_path_strings: Vec < PathString < ' _ > > = Vec :: new ( ) ;
28062816
@@ -2959,8 +2969,11 @@ fn show_candidates(
29592969 append_candidates ( & mut msg, accessible_path_strings) ;
29602970 err. help ( msg) ;
29612971 }
2962- true
2963- } else if !( inaccessible_path_strings. is_empty ( ) || matches ! ( mode, DiagMode :: Import { .. } ) ) {
2972+ showed = true ;
2973+ }
2974+ if !inaccessible_path_strings. is_empty ( )
2975+ && ( !matches ! ( mode, DiagMode :: Import { unresolved_import: false , .. } ) )
2976+ {
29642977 let prefix =
29652978 if let DiagMode :: Pattern = mode { "you might have meant to match on " } else { "" } ;
29662979 if let [ ( name, descr, source_span, note, _) ] = & inaccessible_path_strings[ ..] {
@@ -3023,10 +3036,9 @@ fn show_candidates(
30233036
30243037 err. span_note ( multi_span, msg) ;
30253038 }
3026- true
3027- } else {
3028- false
3039+ showed = true ;
30293040 }
3041+ showed
30303042}
30313043
30323044#[ derive( Debug ) ]
0 commit comments