@@ -884,6 +884,10 @@ pub struct Resolver<'a> {
884
884
/// "self-confirming" import resolutions during import validation.
885
885
unusable_binding : Option < & ' a NameBinding < ' a > > ,
886
886
887
+ // Spans for local variables found during resolution
888
+ // Used for suggestions during error reporting
889
+ local_span_map : NodeMap < Span > ,
890
+
887
891
/// Resolutions for nodes that have a single resolution.
888
892
partial_res_map : NodeMap < PartialRes > ,
889
893
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
@@ -1262,6 +1266,7 @@ impl<'a> Resolver<'a> {
1262
1266
last_import_segment : false ,
1263
1267
unusable_binding : None ,
1264
1268
1269
+ local_span_map : Default :: default ( ) ,
1265
1270
partial_res_map : Default :: default ( ) ,
1266
1271
import_res_map : Default :: default ( ) ,
1267
1272
label_res_map : Default :: default ( ) ,
@@ -1879,7 +1884,6 @@ impl<'a> Resolver<'a> {
1879
1884
ribs,
1880
1885
) ) ) ;
1881
1886
}
1882
-
1883
1887
module = match ribs[ i] . kind {
1884
1888
ModuleRibKind ( module) => module,
1885
1889
MacroDefinition ( def) if def == self . macro_def ( ident. span . ctxt ( ) ) => {
@@ -1890,7 +1894,6 @@ impl<'a> Resolver<'a> {
1890
1894
}
1891
1895
_ => continue ,
1892
1896
} ;
1893
-
1894
1897
match module. kind {
1895
1898
ModuleKind :: Block ( ..) => { } // We can see through blocks
1896
1899
_ => break ,
@@ -1909,17 +1912,19 @@ impl<'a> Resolver<'a> {
1909
1912
return Some ( LexicalScopeBinding :: Item ( binding) ) ;
1910
1913
}
1911
1914
}
1915
+ let returned_item = self
1916
+ . early_resolve_ident_in_lexical_scope (
1917
+ orig_ident,
1918
+ ScopeSet :: Late ( ns, module, record_used_id) ,
1919
+ parent_scope,
1920
+ record_used,
1921
+ record_used,
1922
+ path_span,
1923
+ )
1924
+ . ok ( )
1925
+ . map ( LexicalScopeBinding :: Item ) ;
1912
1926
1913
- self . early_resolve_ident_in_lexical_scope (
1914
- orig_ident,
1915
- ScopeSet :: Late ( ns, module, record_used_id) ,
1916
- parent_scope,
1917
- record_used,
1918
- record_used,
1919
- path_span,
1920
- )
1921
- . ok ( )
1922
- . map ( LexicalScopeBinding :: Item )
1927
+ returned_item
1923
1928
}
1924
1929
1925
1930
fn hygienic_lexical_parent (
@@ -2386,7 +2391,40 @@ impl<'a> Resolver<'a> {
2386
2391
. next ( )
2387
2392
. map_or ( false , |c| c. is_ascii_uppercase ( ) )
2388
2393
{
2389
- ( format ! ( "use of undeclared type `{}`" , ident) , None )
2394
+ // Add check case for similarly named item in alternative namespace
2395
+ let mut suggestion = None ;
2396
+
2397
+ if ribs. is_some ( ) {
2398
+ if let Some ( res) = self . resolve_ident_in_lexical_scope (
2399
+ ident,
2400
+ ValueNS ,
2401
+ parent_scope,
2402
+ None ,
2403
+ path_span,
2404
+ & ribs. unwrap ( ) [ ValueNS ] ,
2405
+ ) {
2406
+ let mut match_span: Option < Span > = None ;
2407
+ match res {
2408
+ LexicalScopeBinding :: Res ( Res :: Local ( id) ) => {
2409
+ match_span =
2410
+ Some ( * self . local_span_map . get ( & id) . unwrap ( ) ) ;
2411
+ }
2412
+ LexicalScopeBinding :: Item ( name_binding) => {
2413
+ match_span = Some ( name_binding. span ) ;
2414
+ }
2415
+ _ => ( ) ,
2416
+ } ;
2417
+ if let Some ( span) = match_span {
2418
+ suggestion = Some ( (
2419
+ vec ! [ ( span, String :: from( "" ) ) ] ,
2420
+ format ! ( "{} is defined here, but is not a type" , ident) ,
2421
+ Applicability :: MaybeIncorrect ,
2422
+ ) ) ;
2423
+ }
2424
+ }
2425
+ }
2426
+
2427
+ ( format ! ( "use of undeclared type `{}`" , ident) , suggestion)
2390
2428
} else {
2391
2429
( format ! ( "use of undeclared crate or module `{}`" , ident) , None )
2392
2430
}
@@ -2797,6 +2835,11 @@ impl<'a> Resolver<'a> {
2797
2835
}
2798
2836
}
2799
2837
2838
+ fn record_local_span ( & mut self , node : NodeId , span : Span ) {
2839
+ debug ! ( "(recording local) recording {:?} for {:?}" , node, span) ;
2840
+ self . local_span_map . insert ( node, span) ;
2841
+ }
2842
+
2800
2843
fn is_accessible_from ( & self , vis : ty:: Visibility , module : Module < ' a > ) -> bool {
2801
2844
vis. is_accessible_from ( module. nearest_parent_mod , self )
2802
2845
}
0 commit comments