@@ -584,6 +584,7 @@ impl<T> ::std::ops::IndexMut<Namespace> for PerNS<T> {
584
584
struct UsePlacementFinder {
585
585
target_module : NodeId ,
586
586
span : Option < Span > ,
587
+ found_use : bool ,
587
588
}
588
589
589
590
impl < ' tcx > Visitor < ' tcx > for UsePlacementFinder {
@@ -611,6 +612,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
611
612
let mut span = item. span ;
612
613
span. hi = span. lo ;
613
614
self . span = Some ( span) ;
615
+ self . found_use = true ;
614
616
return ;
615
617
}
616
618
} ,
@@ -3576,11 +3578,12 @@ impl<'a> Resolver<'a> {
3576
3578
let mut finder = UsePlacementFinder {
3577
3579
target_module : node_id,
3578
3580
span : None ,
3581
+ found_use : false ,
3579
3582
} ;
3580
3583
visit:: walk_crate ( & mut finder, krate) ;
3581
3584
if !candidates. is_empty ( ) {
3582
3585
let span = finder. span . expect ( "did not find module" ) ;
3583
- show_candidates ( & mut err, span, & candidates, better) ;
3586
+ show_candidates ( & mut err, span, & candidates, better, finder . found_use ) ;
3584
3587
}
3585
3588
err. emit ( ) ;
3586
3589
}
@@ -3776,7 +3779,8 @@ fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (Span, String, St
3776
3779
fn show_candidates ( err : & mut DiagnosticBuilder ,
3777
3780
span : Span ,
3778
3781
candidates : & [ ImportSuggestion ] ,
3779
- better : bool ) {
3782
+ better : bool ,
3783
+ found_use : bool ) {
3780
3784
3781
3785
// we want consistent results across executions, but candidates are produced
3782
3786
// by iterating through a hash map, so make sure they are ordered:
@@ -3792,7 +3796,14 @@ fn show_candidates(err: &mut DiagnosticBuilder,
3792
3796
let msg = format ! ( "possible {}candidate{} into scope" , better, msg_diff) ;
3793
3797
3794
3798
for candidate in & mut path_strings {
3795
- * candidate = format ! ( "use {};\n " , candidate) ;
3799
+ // produce an additional newline to separate the new use statement
3800
+ // from the directly following item.
3801
+ let additional_newline = if found_use {
3802
+ ""
3803
+ } else {
3804
+ "\n "
3805
+ } ;
3806
+ * candidate = format ! ( "use {};\n {}" , candidate, additional_newline) ;
3796
3807
}
3797
3808
3798
3809
err. span_suggestions ( span, & msg, path_strings) ;
0 commit comments