@@ -884,9 +884,9 @@ 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 > ,
887
+ // Spans for local variables found during pattern resolution.
888
+ // Used for suggestions during error reporting.
889
+ pat_span_map : NodeMap < Span > ,
890
890
891
891
/// Resolutions for nodes that have a single resolution.
892
892
partial_res_map : NodeMap < PartialRes > ,
@@ -1266,7 +1266,7 @@ impl<'a> Resolver<'a> {
1266
1266
last_import_segment : false ,
1267
1267
unusable_binding : None ,
1268
1268
1269
- local_span_map : Default :: default ( ) ,
1269
+ pat_span_map : Default :: default ( ) ,
1270
1270
partial_res_map : Default :: default ( ) ,
1271
1271
import_res_map : Default :: default ( ) ,
1272
1272
label_res_map : Default :: default ( ) ,
@@ -1884,6 +1884,7 @@ impl<'a> Resolver<'a> {
1884
1884
ribs,
1885
1885
) ) ) ;
1886
1886
}
1887
+
1887
1888
module = match ribs[ i] . kind {
1888
1889
ModuleRibKind ( module) => module,
1889
1890
MacroDefinition ( def) if def == self . macro_def ( ident. span . ctxt ( ) ) => {
@@ -1894,6 +1895,7 @@ impl<'a> Resolver<'a> {
1894
1895
}
1895
1896
_ => continue ,
1896
1897
} ;
1898
+
1897
1899
match module. kind {
1898
1900
ModuleKind :: Block ( ..) => { } // We can see through blocks
1899
1901
_ => break ,
@@ -1912,19 +1914,16 @@ impl<'a> Resolver<'a> {
1912
1914
return Some ( LexicalScopeBinding :: Item ( binding) ) ;
1913
1915
}
1914
1916
}
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 ) ;
1926
-
1927
- returned_item
1917
+ self . early_resolve_ident_in_lexical_scope (
1918
+ orig_ident,
1919
+ ScopeSet :: Late ( ns, module, record_used_id) ,
1920
+ parent_scope,
1921
+ record_used,
1922
+ record_used,
1923
+ path_span,
1924
+ )
1925
+ . ok ( )
1926
+ . map ( LexicalScopeBinding :: Item )
1928
1927
}
1929
1928
1930
1929
fn hygienic_lexical_parent (
@@ -2391,38 +2390,57 @@ impl<'a> Resolver<'a> {
2391
2390
. next ( )
2392
2391
. map_or ( false , |c| c. is_ascii_uppercase ( ) )
2393
2392
{
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 (
2393
+ // Check whether the name refers to an item in the value namespace.
2394
+ let suggestion = if ribs. is_some ( ) {
2395
+ let match_span = match self . resolve_ident_in_lexical_scope (
2399
2396
ident,
2400
2397
ValueNS ,
2401
2398
parent_scope,
2402
2399
None ,
2403
2400
path_span,
2404
2401
& ribs. unwrap ( ) [ ValueNS ] ,
2405
2402
) {
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
- ) ) ;
2403
+ // Name matches a local variable. For example:
2404
+ // ```
2405
+ // fn f() {
2406
+ // let Foo: &str = "";
2407
+ // println!("{}", Foo::Bar); // Name refers to local
2408
+ // // variable `Foo`.
2409
+ // }
2410
+ // ```
2411
+ Some ( LexicalScopeBinding :: Res ( Res :: Local ( id) ) ) => {
2412
+ Some ( * self . pat_span_map . get ( & id) . unwrap ( ) )
2423
2413
}
2414
+
2415
+ // Name matches item from a local name binding
2416
+ // created by `use` declaration. For example:
2417
+ // ```
2418
+ // pub Foo: &str = "";
2419
+ //
2420
+ // mod submod {
2421
+ // use super::Foo;
2422
+ // println!("{}", Foo::Bar); // Name refers to local
2423
+ // // binding `Foo`.
2424
+ // }
2425
+ // ```
2426
+ Some ( LexicalScopeBinding :: Item ( name_binding) ) => {
2427
+ Some ( name_binding. span )
2428
+ }
2429
+ _ => None ,
2430
+ } ;
2431
+
2432
+ if let Some ( span) = match_span {
2433
+ Some ( (
2434
+ vec ! [ ( span, String :: from( "" ) ) ] ,
2435
+ format ! ( "`{}` is defined here, but is not a type" , ident) ,
2436
+ Applicability :: MaybeIncorrect ,
2437
+ ) )
2438
+ } else {
2439
+ None
2424
2440
}
2425
- }
2441
+ } else {
2442
+ None
2443
+ } ;
2426
2444
2427
2445
( format ! ( "use of undeclared type `{}`" , ident) , suggestion)
2428
2446
} else {
@@ -2835,9 +2853,9 @@ impl<'a> Resolver<'a> {
2835
2853
}
2836
2854
}
2837
2855
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) ;
2856
+ fn record_pat_span ( & mut self , node : NodeId , span : Span ) {
2857
+ debug ! ( "(recording pat ) recording {:?} for {:?}" , node, span) ;
2858
+ self . pat_span_map . insert ( node, span) ;
2841
2859
}
2842
2860
2843
2861
fn is_accessible_from ( & self , vis : ty:: Visibility , module : Module < ' a > ) -> bool {
0 commit comments