@@ -5,10 +5,10 @@ use rustc_ast::visit::{self, Visitor};
5
5
use rustc_ast:: { self as ast, Crate , ItemKind , ModKind , NodeId , Path , CRATE_NODE_ID } ;
6
6
use rustc_ast_pretty:: pprust;
7
7
use rustc_data_structures:: fx:: FxHashSet ;
8
- use rustc_errors:: struct_span_err;
9
8
use rustc_errors:: {
10
9
pluralize, Applicability , Diagnostic , DiagnosticBuilder , ErrorGuaranteed , MultiSpan ,
11
10
} ;
11
+ use rustc_errors:: { struct_span_err, SuggestionStyle } ;
12
12
use rustc_feature:: BUILTIN_ATTRIBUTES ;
13
13
use rustc_hir:: def:: Namespace :: { self , * } ;
14
14
use rustc_hir:: def:: { self , CtorKind , CtorOf , DefKind , NonMacroAttrKind , PerNS } ;
@@ -2418,7 +2418,7 @@ fn show_candidates(
2418
2418
}
2419
2419
2420
2420
if let Some ( span) = use_placement_span {
2421
- let add_use = match mode {
2421
+ let ( add_use, trailing ) = match mode {
2422
2422
DiagnosticMode :: Pattern => {
2423
2423
err. span_suggestions (
2424
2424
span,
@@ -2428,21 +2428,23 @@ fn show_candidates(
2428
2428
) ;
2429
2429
return ;
2430
2430
}
2431
- DiagnosticMode :: Import => "" ,
2432
- DiagnosticMode :: Normal => "use " ,
2431
+ DiagnosticMode :: Import => ( "" , "" ) ,
2432
+ DiagnosticMode :: Normal => ( "use " , "; \n " ) ,
2433
2433
} ;
2434
2434
for candidate in & mut accessible_path_strings {
2435
2435
// produce an additional newline to separate the new use statement
2436
2436
// 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 ) ;
2439
2440
}
2440
2441
2441
- err. span_suggestions (
2442
+ err. span_suggestions_with_style (
2442
2443
span,
2443
2444
& msg,
2444
2445
accessible_path_strings. into_iter ( ) . map ( |a| a. 0 ) ,
2445
2446
Applicability :: MaybeIncorrect ,
2447
+ SuggestionStyle :: ShowAlways ,
2446
2448
) ;
2447
2449
if let [ first, .., last] = & path[ ..] {
2448
2450
let sp = first. ident . span . until ( last. ident . span ) ;
0 commit comments