@@ -631,7 +631,6 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
631
631
} ,
632
632
}
633
633
}
634
- assert ! ( self . span. is_some( ) , "a file can't have no items and emit suggestions" ) ;
635
634
}
636
635
}
637
636
@@ -3562,8 +3561,7 @@ impl<'a> Resolver<'a> {
3562
3561
} ;
3563
3562
visit:: walk_crate ( & mut finder, krate) ;
3564
3563
if !candidates. is_empty ( ) {
3565
- let span = finder. span . expect ( "did not find module" ) ;
3566
- show_candidates ( & mut err, span, & candidates, better, finder. found_use ) ;
3564
+ show_candidates ( & mut err, finder. span , & candidates, better, finder. found_use ) ;
3567
3565
}
3568
3566
err. emit ( ) ;
3569
3567
}
@@ -3757,7 +3755,8 @@ fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (Span, String, St
3757
3755
/// entities with that name in all crates. This method allows outputting the
3758
3756
/// results of this search in a programmer-friendly way
3759
3757
fn show_candidates ( err : & mut DiagnosticBuilder ,
3760
- span : Span ,
3758
+ // This is `None` if all placement locations are inside expansions
3759
+ span : Option < Span > ,
3761
3760
candidates : & [ ImportSuggestion ] ,
3762
3761
better : bool ,
3763
3762
found_use : bool ) {
@@ -3775,18 +3774,27 @@ fn show_candidates(err: &mut DiagnosticBuilder,
3775
3774
} ;
3776
3775
let msg = format ! ( "possible {}candidate{} into scope" , better, msg_diff) ;
3777
3776
3778
- for candidate in & mut path_strings {
3779
- // produce an additional newline to separate the new use statement
3780
- // from the directly following item.
3781
- let additional_newline = if found_use {
3782
- ""
3783
- } else {
3784
- "\n "
3785
- } ;
3786
- * candidate = format ! ( "use {};\n {}" , candidate, additional_newline) ;
3787
- }
3777
+ if let Some ( span) = span {
3778
+ for candidate in & mut path_strings {
3779
+ // produce an additional newline to separate the new use statement
3780
+ // from the directly following item.
3781
+ let additional_newline = if found_use {
3782
+ ""
3783
+ } else {
3784
+ "\n "
3785
+ } ;
3786
+ * candidate = format ! ( "use {};\n {}" , candidate, additional_newline) ;
3787
+ }
3788
3788
3789
- err. span_suggestions ( span, & msg, path_strings) ;
3789
+ err. span_suggestions ( span, & msg, path_strings) ;
3790
+ } else {
3791
+ let mut msg = msg;
3792
+ msg. push ( ':' ) ;
3793
+ for candidate in path_strings {
3794
+ msg. push ( '\n' ) ;
3795
+ msg. push_str ( & candidate) ;
3796
+ }
3797
+ }
3790
3798
}
3791
3799
3792
3800
/// A somewhat inefficient routine to obtain the name of a module.
0 commit comments