@@ -584,6 +584,7 @@ impl<T> ::std::ops::IndexMut<Namespace> for PerNS<T> {
584584struct UsePlacementFinder {
585585 target_module : NodeId ,
586586 span : Option < Span > ,
587+ found_use : bool ,
587588}
588589
589590impl < ' tcx > Visitor < ' tcx > for UsePlacementFinder {
@@ -611,6 +612,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
611612 let mut span = item. span ;
612613 span. hi = span. lo ;
613614 self . span = Some ( span) ;
615+ self . found_use = true ;
614616 return ;
615617 }
616618 } ,
@@ -3576,11 +3578,12 @@ impl<'a> Resolver<'a> {
35763578 let mut finder = UsePlacementFinder {
35773579 target_module : node_id,
35783580 span : None ,
3581+ found_use : false ,
35793582 } ;
35803583 visit:: walk_crate ( & mut finder, krate) ;
35813584 if !candidates. is_empty ( ) {
35823585 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 ) ;
35843587 }
35853588 err. emit ( ) ;
35863589 }
@@ -3776,7 +3779,8 @@ fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (Span, String, St
37763779fn show_candidates ( err : & mut DiagnosticBuilder ,
37773780 span : Span ,
37783781 candidates : & [ ImportSuggestion ] ,
3779- better : bool ) {
3782+ better : bool ,
3783+ found_use : bool ) {
37803784
37813785 // we want consistent results across executions, but candidates are produced
37823786 // by iterating through a hash map, so make sure they are ordered:
@@ -3792,7 +3796,14 @@ fn show_candidates(err: &mut DiagnosticBuilder,
37923796 let msg = format ! ( "possible {}candidate{} into scope" , better, msg_diff) ;
37933797
37943798 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) ;
37963807 }
37973808
37983809 err. span_suggestions ( span, & msg, path_strings) ;
0 commit comments