@@ -2084,10 +2084,25 @@ impl<'a> Resolver<'a> {
20842084 let expected = source. descr_expected ( ) ;
20852085 let path_str = names_to_string ( path) ;
20862086 let code = source. error_code ( def. is_some ( ) ) ;
2087- let base_msg = if let Some ( def) = def {
2088- format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str)
2087+ let ( base_msg, fallback_label) = if let Some ( def) = def {
2088+ ( format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str) ,
2089+ format ! ( "not a {}" , expected) )
20892090 } else {
2090- format ! ( "unresolved {} `{}`" , expected, path_str)
2091+ let item_str = path[ path. len ( ) - 1 ] ;
2092+ let ( mod_prefix, mod_str) = if path. len ( ) == 1 {
2093+ ( format ! ( "" ) , format ! ( "this scope" ) )
2094+ } else if path. len ( ) == 2 && path[ 0 ] . name == keywords:: CrateRoot . name ( ) {
2095+ ( format ! ( "" ) , format ! ( "the crate root" ) )
2096+ } else {
2097+ let mod_path = & path[ ..path. len ( ) - 1 ] ;
2098+ let mod_prefix = match this. resolve_path ( mod_path, Some ( TypeNS ) , None ) {
2099+ PathResult :: Module ( module) => module. def ( ) ,
2100+ _ => None ,
2101+ } . map_or ( format ! ( "" ) , |def| format ! ( "{} " , def. kind_name( ) ) ) ;
2102+ ( mod_prefix, format ! ( "`{}`" , names_to_string( mod_path) ) )
2103+ } ;
2104+ ( format ! ( "cannot find {} `{}` in {}{}" , expected, item_str, mod_prefix, mod_str) ,
2105+ format ! ( "not found in {}" , mod_str) )
20912106 } ;
20922107 let mut err = this. session . struct_span_err_with_code ( span, & base_msg, code) ;
20932108
@@ -2177,12 +2192,8 @@ impl<'a> Resolver<'a> {
21772192 }
21782193 }
21792194
2180- // Fallback labels.
2181- if def. is_some ( ) {
2182- err. span_label ( span, & format ! ( "not a {}" , expected) ) ;
2183- } else {
2184- err. span_label ( span, & format ! ( "no resolution found" ) ) ;
2185- }
2195+ // Fallback label.
2196+ err. span_label ( span, & fallback_label) ;
21862197 err
21872198 } ;
21882199 let report_errors = |this : & mut Self , def : Option < Def > | {
@@ -2983,8 +2994,8 @@ impl<'a> Resolver<'a> {
29832994 let participle = |binding : & NameBinding | {
29842995 if binding. is_import ( ) { "imported" } else { "defined" }
29852996 } ;
2986- let msg1 = format ! ( "`{}` could resolve to the name {} here" , name, participle( b1) ) ;
2987- let msg2 = format ! ( "`{}` could also resolve to the name {} here" , name, participle( b2) ) ;
2997+ let msg1 = format ! ( "`{}` could refer to the name {} here" , name, participle( b1) ) ;
2998+ let msg2 = format ! ( "`{}` could also refer to the name {} here" , name, participle( b2) ) ;
29882999 let note = if !lexical && b1. is_glob_import ( ) {
29893000 format ! ( "consider adding an explicit import of `{}` to disambiguate" , name)
29903001 } else if let Def :: Macro ( ..) = b1. def ( ) {
0 commit comments