@@ -637,7 +637,6 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
637
637
} ,
638
638
}
639
639
}
640
- assert ! ( self . span. is_some( ) , "a file can't have no items and emit suggestions" ) ;
641
640
}
642
641
}
643
642
@@ -3568,8 +3567,7 @@ impl<'a> Resolver<'a> {
3568
3567
} ;
3569
3568
visit:: walk_crate ( & mut finder, krate) ;
3570
3569
if !candidates. is_empty ( ) {
3571
- let span = finder. span . expect ( "did not find module" ) ;
3572
- show_candidates ( & mut err, span, & candidates, better, finder. found_use ) ;
3570
+ show_candidates ( & mut err, finder. span , & candidates, better, finder. found_use ) ;
3573
3571
}
3574
3572
err. emit ( ) ;
3575
3573
}
@@ -3763,7 +3761,8 @@ fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (Span, String, St
3763
3761
/// entities with that name in all crates. This method allows outputting the
3764
3762
/// results of this search in a programmer-friendly way
3765
3763
fn show_candidates ( err : & mut DiagnosticBuilder ,
3766
- span : Span ,
3764
+ // This is `None` if all placement locations are inside expansions
3765
+ span : Option < Span > ,
3767
3766
candidates : & [ ImportSuggestion ] ,
3768
3767
better : bool ,
3769
3768
found_use : bool ) {
@@ -3781,18 +3780,27 @@ fn show_candidates(err: &mut DiagnosticBuilder,
3781
3780
} ;
3782
3781
let msg = format ! ( "possible {}candidate{} into scope" , better, msg_diff) ;
3783
3782
3784
- for candidate in & mut path_strings {
3785
- // produce an additional newline to separate the new use statement
3786
- // from the directly following item.
3787
- let additional_newline = if found_use {
3788
- ""
3789
- } else {
3790
- "\n "
3791
- } ;
3792
- * candidate = format ! ( "use {};\n {}" , candidate, additional_newline) ;
3793
- }
3783
+ if let Some ( span) = span {
3784
+ for candidate in & mut path_strings {
3785
+ // produce an additional newline to separate the new use statement
3786
+ // from the directly following item.
3787
+ let additional_newline = if found_use {
3788
+ ""
3789
+ } else {
3790
+ "\n "
3791
+ } ;
3792
+ * candidate = format ! ( "use {};\n {}" , candidate, additional_newline) ;
3793
+ }
3794
3794
3795
- err. span_suggestions ( span, & msg, path_strings) ;
3795
+ err. span_suggestions ( span, & msg, path_strings) ;
3796
+ } else {
3797
+ let mut msg = msg;
3798
+ msg. push ( ':' ) ;
3799
+ for candidate in path_strings {
3800
+ msg. push ( '\n' ) ;
3801
+ msg. push_str ( & candidate) ;
3802
+ }
3803
+ }
3796
3804
}
3797
3805
3798
3806
/// A somewhat inefficient routine to obtain the name of a module.
0 commit comments