@@ -539,6 +539,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
539
539
( & Failed ( _) , & Failed ( _) ) => {
540
540
let resolutions = target_module. resolutions . borrow ( ) ;
541
541
let names = resolutions. iter ( ) . filter_map ( |( & ( ref name, _) , resolution) | {
542
+ if * name == source { return None ; } // Never suggest the same name
542
543
match * resolution. borrow ( ) {
543
544
NameResolution { binding : Some ( _) , .. } => Some ( name) ,
544
545
NameResolution { single_imports : SingleImports :: None , .. } => None ,
@@ -549,9 +550,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
549
550
Some ( name) => format ! ( ". Did you mean to use `{}`?" , name) ,
550
551
None => "" . to_owned ( ) ,
551
552
} ;
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
+ } ;
555
559
return Failed ( Some ( ( directive. span , msg) ) ) ;
556
560
}
557
561
_ => ( ) ,
0 commit comments