@@ -1736,7 +1736,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1736
1736
}
1737
1737
1738
1738
fn report_privacy_error ( & mut self , privacy_error : & PrivacyError < ' a > ) {
1739
- let PrivacyError { ident, binding, outermost_res, parent_scope, dedup_span } =
1739
+ let PrivacyError { ident, binding, outermost_res, parent_scope, single_nested , dedup_span } =
1740
1740
* privacy_error;
1741
1741
1742
1742
let res = binding. res ( ) ;
@@ -1775,7 +1775,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1775
1775
& import_suggestions,
1776
1776
Instead :: Yes ,
1777
1777
FoundUse :: Yes ,
1778
- DiagMode :: Import ,
1778
+ DiagMode :: Import { append : single_nested } ,
1779
1779
vec ! [ ] ,
1780
1780
"" ,
1781
1781
) ;
@@ -2701,7 +2701,11 @@ pub(crate) enum DiagMode {
2701
2701
/// The binding is part of a pattern
2702
2702
Pattern ,
2703
2703
/// The binding is part of a use statement
2704
- Import ,
2704
+ Import {
2705
+ /// `true` mean add the tips afterward for case `use a::{b,c}`,
2706
+ /// rather than replacing within.
2707
+ append : bool ,
2708
+ } ,
2705
2709
}
2706
2710
2707
2711
pub ( crate ) fn import_candidates (
@@ -2726,6 +2730,8 @@ pub(crate) fn import_candidates(
2726
2730
) ;
2727
2731
}
2728
2732
2733
+ type PathString < ' a > = ( String , & ' a str , Option < DefId > , & ' a Option < String > , bool ) ;
2734
+
2729
2735
/// When an entity with a given name is not available in scope, we search for
2730
2736
/// entities with that name in all crates. This method allows outputting the
2731
2737
/// results of this search in a programmer-friendly way. If any entities are
@@ -2746,10 +2752,8 @@ fn show_candidates(
2746
2752
return false ;
2747
2753
}
2748
2754
2749
- let mut accessible_path_strings: Vec < ( String , & str , Option < DefId > , & Option < String > , bool ) > =
2750
- Vec :: new ( ) ;
2751
- let mut inaccessible_path_strings: Vec < ( String , & str , Option < DefId > , & Option < String > , bool ) > =
2752
- Vec :: new ( ) ;
2755
+ let mut accessible_path_strings: Vec < PathString < ' _ > > = Vec :: new ( ) ;
2756
+ let mut inaccessible_path_strings: Vec < PathString < ' _ > > = Vec :: new ( ) ;
2753
2757
2754
2758
candidates. iter ( ) . for_each ( |c| {
2755
2759
if c. accessible {
@@ -2811,6 +2815,15 @@ fn show_candidates(
2811
2815
err. note ( note. clone ( ) ) ;
2812
2816
}
2813
2817
2818
+ let append_candidates = |msg : & mut String , accessible_path_strings : Vec < PathString < ' _ > > | {
2819
+ msg. push ( ':' ) ;
2820
+
2821
+ for candidate in accessible_path_strings {
2822
+ msg. push ( '\n' ) ;
2823
+ msg. push_str ( & candidate. 0 ) ;
2824
+ }
2825
+ } ;
2826
+
2814
2827
if let Some ( span) = use_placement_span {
2815
2828
let ( add_use, trailing) = match mode {
2816
2829
DiagMode :: Pattern => {
@@ -2822,7 +2835,7 @@ fn show_candidates(
2822
2835
) ;
2823
2836
return true ;
2824
2837
}
2825
- DiagMode :: Import => ( "" , "" ) ,
2838
+ DiagMode :: Import { .. } => ( "" , "" ) ,
2826
2839
DiagMode :: Normal => ( "use " , ";\n " ) ,
2827
2840
} ;
2828
2841
for candidate in & mut accessible_path_strings {
@@ -2839,13 +2852,22 @@ fn show_candidates(
2839
2852
format ! ( "{add_use}{}{append}{trailing}{additional_newline}" , & candidate. 0 ) ;
2840
2853
}
2841
2854
2842
- err. span_suggestions_with_style (
2843
- span,
2844
- msg,
2845
- accessible_path_strings. into_iter ( ) . map ( |a| a. 0 ) ,
2846
- Applicability :: MaybeIncorrect ,
2847
- SuggestionStyle :: ShowAlways ,
2848
- ) ;
2855
+ match mode {
2856
+ DiagMode :: Import { append : true , .. } => {
2857
+ append_candidates ( & mut msg, accessible_path_strings) ;
2858
+ err. span_help ( span, msg) ;
2859
+ }
2860
+ _ => {
2861
+ err. span_suggestions_with_style (
2862
+ span,
2863
+ msg,
2864
+ accessible_path_strings. into_iter ( ) . map ( |a| a. 0 ) ,
2865
+ Applicability :: MaybeIncorrect ,
2866
+ SuggestionStyle :: ShowAlways ,
2867
+ ) ;
2868
+ }
2869
+ }
2870
+
2849
2871
if let [ first, .., last] = & path[ ..] {
2850
2872
let sp = first. ident . span . until ( last. ident . span ) ;
2851
2873
// Our suggestion is empty, so make sure the span is not empty (or we'd ICE).
@@ -2860,17 +2882,11 @@ fn show_candidates(
2860
2882
}
2861
2883
}
2862
2884
} else {
2863
- msg. push ( ':' ) ;
2864
-
2865
- for candidate in accessible_path_strings {
2866
- msg. push ( '\n' ) ;
2867
- msg. push_str ( & candidate. 0 ) ;
2868
- }
2869
-
2885
+ append_candidates ( & mut msg, accessible_path_strings) ;
2870
2886
err. help ( msg) ;
2871
2887
}
2872
2888
true
2873
- } else if !( inaccessible_path_strings. is_empty ( ) || matches ! ( mode, DiagMode :: Import ) ) {
2889
+ } else if !( inaccessible_path_strings. is_empty ( ) || matches ! ( mode, DiagMode :: Import { .. } ) ) {
2874
2890
let prefix =
2875
2891
if let DiagMode :: Pattern = mode { "you might have meant to match on " } else { "" } ;
2876
2892
if let [ ( name, descr, def_id, note, _) ] = & inaccessible_path_strings[ ..] {
0 commit comments