@@ -539,6 +539,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
539539 ( & Failed ( _) , & Failed ( _) ) => {
540540 let resolutions = target_module. resolutions . borrow ( ) ;
541541 let names = resolutions. iter ( ) . filter_map ( |( & ( ref name, _) , resolution) | {
542+ if * name == source { return None ; } // Never suggest the same name
542543 match * resolution. borrow ( ) {
543544 NameResolution { binding : Some ( _) , .. } => Some ( name) ,
544545 NameResolution { single_imports : SingleImports :: None , .. } => None ,
@@ -549,9 +550,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
549550 Some ( name) => format ! ( ". Did you mean to use `{}`?" , name) ,
550551 None => "" . to_owned ( ) ,
551552 } ;
552- let msg = format ! ( "There is no `{}` in `{}`{}" ,
553- source,
554- module_to_string( target_module) , lev_suggestion) ;
553+ let module_str = module_to_string ( target_module) ;
554+ let msg = if & module_str == "???" {
555+ format ! ( "There is no `{}` in the crate root{}" , source, lev_suggestion)
556+ } else {
557+ format ! ( "There is no `{}` in `{}`{}" , source, module_str, lev_suggestion)
558+ } ;
555559 return Failed ( Some ( ( directive. span , msg) ) ) ;
556560 }
557561 _ => ( ) ,
0 commit comments