@@ -1325,9 +1325,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1325
1325
} )
1326
1326
}
1327
1327
1328
- // If only some candidates are accessible, take just them
1328
+ // If only some candidates are accessible, add note to make it public
1329
1329
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
+ } ) ;
1331
1338
}
1332
1339
1333
1340
candidates
@@ -1794,7 +1801,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1794
1801
& import_suggestions,
1795
1802
Instead :: Yes ,
1796
1803
FoundUse :: Yes ,
1797
- DiagMode :: Import { append : single_nested } ,
1804
+ DiagMode :: Import { append : single_nested, unresolved_import : false } ,
1798
1805
vec ! [ ] ,
1799
1806
"" ,
1800
1807
) ;
@@ -2751,6 +2758,8 @@ pub(crate) enum DiagMode {
2751
2758
Pattern ,
2752
2759
/// The binding is part of a use statement
2753
2760
Import {
2761
+ /// `true` means diagnostics is for unresolved import
2762
+ unresolved_import : bool ,
2754
2763
/// `true` mean add the tips afterward for case `use a::{b,c}`,
2755
2764
/// rather than replacing within.
2756
2765
append : bool ,
@@ -2801,6 +2810,7 @@ fn show_candidates(
2801
2810
return false ;
2802
2811
}
2803
2812
2813
+ let mut showed = false ;
2804
2814
let mut accessible_path_strings: Vec < PathString < ' _ > > = Vec :: new ( ) ;
2805
2815
let mut inaccessible_path_strings: Vec < PathString < ' _ > > = Vec :: new ( ) ;
2806
2816
@@ -2959,8 +2969,11 @@ fn show_candidates(
2959
2969
append_candidates ( & mut msg, accessible_path_strings) ;
2960
2970
err. help ( msg) ;
2961
2971
}
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
+ {
2964
2977
let prefix =
2965
2978
if let DiagMode :: Pattern = mode { "you might have meant to match on " } else { "" } ;
2966
2979
if let [ ( name, descr, source_span, note, _) ] = & inaccessible_path_strings[ ..] {
@@ -3023,10 +3036,9 @@ fn show_candidates(
3023
3036
3024
3037
err. span_note ( multi_span, msg) ;
3025
3038
}
3026
- true
3027
- } else {
3028
- false
3039
+ showed = true ;
3029
3040
}
3041
+ showed
3030
3042
}
3031
3043
3032
3044
#[ derive( Debug ) ]
0 commit comments