@@ -5,10 +5,10 @@ use rustc_ast::visit::{self, Visitor};
55use rustc_ast:: { self as ast, Crate , ItemKind , ModKind , NodeId , Path , CRATE_NODE_ID } ;
66use rustc_ast_pretty:: pprust;
77use rustc_data_structures:: fx:: FxHashSet ;
8- use rustc_errors:: struct_span_err;
98use rustc_errors:: {
109 pluralize, Applicability , Diagnostic , DiagnosticBuilder , ErrorGuaranteed , MultiSpan ,
1110} ;
11+ use rustc_errors:: { struct_span_err, SuggestionStyle } ;
1212use rustc_feature:: BUILTIN_ATTRIBUTES ;
1313use rustc_hir:: def:: Namespace :: { self , * } ;
1414use rustc_hir:: def:: { self , CtorKind , CtorOf , DefKind , NonMacroAttrKind , PerNS } ;
@@ -2418,7 +2418,7 @@ fn show_candidates(
24182418 }
24192419
24202420 if let Some ( span) = use_placement_span {
2421- let add_use = match mode {
2421+ let ( add_use, trailing ) = match mode {
24222422 DiagnosticMode :: Pattern => {
24232423 err. span_suggestions (
24242424 span,
@@ -2428,21 +2428,23 @@ fn show_candidates(
24282428 ) ;
24292429 return ;
24302430 }
2431- DiagnosticMode :: Import => "" ,
2432- DiagnosticMode :: Normal => "use " ,
2431+ DiagnosticMode :: Import => ( "" , "" ) ,
2432+ DiagnosticMode :: Normal => ( "use " , "; \n " ) ,
24332433 } ;
24342434 for candidate in & mut accessible_path_strings {
24352435 // produce an additional newline to separate the new use statement
24362436 // from the directly following item.
2437- let additional_newline = if let FoundUse :: Yes = found_use { "" } else { "\n " } ;
2438- candidate. 0 = format ! ( "{add_use}{}{append};\n {additional_newline}" , & candidate. 0 ) ;
2437+ let additional_newline = if let FoundUse :: No = found_use && let DiagnosticMode :: Normal = mode { "\n " } else { "" } ;
2438+ candidate. 0 =
2439+ format ! ( "{add_use}{}{append}{trailing}{additional_newline}" , & candidate. 0 ) ;
24392440 }
24402441
2441- err. span_suggestions (
2442+ err. span_suggestions_with_style (
24422443 span,
24432444 & msg,
24442445 accessible_path_strings. into_iter ( ) . map ( |a| a. 0 ) ,
24452446 Applicability :: MaybeIncorrect ,
2447+ SuggestionStyle :: ShowAlways ,
24462448 ) ;
24472449 if let [ first, .., last] = & path[ ..] {
24482450 let sp = first. ident . span . until ( last. ident . span ) ;
@@ -2463,7 +2465,7 @@ fn show_candidates(
24632465 msg. push_str ( & candidate. 0 ) ;
24642466 }
24652467
2466- err. note ( & msg) ;
2468+ err. help ( & msg) ;
24672469 }
24682470 } else if !matches ! ( mode, DiagnosticMode :: Import ) {
24692471 assert ! ( !inaccessible_path_strings. is_empty( ) ) ;
0 commit comments