@@ -1736,7 +1736,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17361736 }
17371737
17381738 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 } =
17401740 * privacy_error;
17411741
17421742 let res = binding. res ( ) ;
@@ -1775,7 +1775,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17751775 & import_suggestions,
17761776 Instead :: Yes ,
17771777 FoundUse :: Yes ,
1778- DiagMode :: Import ,
1778+ DiagMode :: Import { append : single_nested } ,
17791779 vec ! [ ] ,
17801780 "" ,
17811781 ) ;
@@ -2701,7 +2701,11 @@ pub(crate) enum DiagMode {
27012701 /// The binding is part of a pattern
27022702 Pattern ,
27032703 /// 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+ } ,
27052709}
27062710
27072711pub ( crate ) fn import_candidates (
@@ -2726,6 +2730,8 @@ pub(crate) fn import_candidates(
27262730 ) ;
27272731}
27282732
2733+ type PathString < ' a > = ( String , & ' a str , Option < DefId > , & ' a Option < String > , bool ) ;
2734+
27292735/// When an entity with a given name is not available in scope, we search for
27302736/// entities with that name in all crates. This method allows outputting the
27312737/// results of this search in a programmer-friendly way. If any entities are
@@ -2746,10 +2752,8 @@ fn show_candidates(
27462752 return false ;
27472753 }
27482754
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 ( ) ;
27532757
27542758 candidates. iter ( ) . for_each ( |c| {
27552759 if c. accessible {
@@ -2811,6 +2815,15 @@ fn show_candidates(
28112815 err. note ( note. clone ( ) ) ;
28122816 }
28132817
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+
28142827 if let Some ( span) = use_placement_span {
28152828 let ( add_use, trailing) = match mode {
28162829 DiagMode :: Pattern => {
@@ -2822,7 +2835,7 @@ fn show_candidates(
28222835 ) ;
28232836 return true ;
28242837 }
2825- DiagMode :: Import => ( "" , "" ) ,
2838+ DiagMode :: Import { .. } => ( "" , "" ) ,
28262839 DiagMode :: Normal => ( "use " , ";\n " ) ,
28272840 } ;
28282841 for candidate in & mut accessible_path_strings {
@@ -2839,13 +2852,22 @@ fn show_candidates(
28392852 format ! ( "{add_use}{}{append}{trailing}{additional_newline}" , & candidate. 0 ) ;
28402853 }
28412854
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+
28492871 if let [ first, .., last] = & path[ ..] {
28502872 let sp = first. ident . span . until ( last. ident . span ) ;
28512873 // Our suggestion is empty, so make sure the span is not empty (or we'd ICE).
@@ -2860,17 +2882,11 @@ fn show_candidates(
28602882 }
28612883 }
28622884 } 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) ;
28702886 err. help ( msg) ;
28712887 }
28722888 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 { .. } ) ) {
28742890 let prefix =
28752891 if let DiagMode :: Pattern = mode { "you might have meant to match on " } else { "" } ;
28762892 if let [ ( name, descr, def_id, note, _) ] = & inaccessible_path_strings[ ..] {
0 commit comments