@@ -884,9 +884,9 @@ pub struct Resolver<'a> {
884884 /// "self-confirming" import resolutions during import validation.
885885 unusable_binding : Option < & ' a NameBinding < ' a > > ,
886886
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 > ,
890890
891891 /// Resolutions for nodes that have a single resolution.
892892 partial_res_map : NodeMap < PartialRes > ,
@@ -1266,7 +1266,7 @@ impl<'a> Resolver<'a> {
12661266 last_import_segment : false ,
12671267 unusable_binding : None ,
12681268
1269- local_span_map : Default :: default ( ) ,
1269+ pat_span_map : Default :: default ( ) ,
12701270 partial_res_map : Default :: default ( ) ,
12711271 import_res_map : Default :: default ( ) ,
12721272 label_res_map : Default :: default ( ) ,
@@ -1884,6 +1884,7 @@ impl<'a> Resolver<'a> {
18841884 ribs,
18851885 ) ) ) ;
18861886 }
1887+
18871888 module = match ribs[ i] . kind {
18881889 ModuleRibKind ( module) => module,
18891890 MacroDefinition ( def) if def == self . macro_def ( ident. span . ctxt ( ) ) => {
@@ -1894,6 +1895,7 @@ impl<'a> Resolver<'a> {
18941895 }
18951896 _ => continue ,
18961897 } ;
1898+
18971899 match module. kind {
18981900 ModuleKind :: Block ( ..) => { } // We can see through blocks
18991901 _ => break ,
@@ -1912,19 +1914,16 @@ impl<'a> Resolver<'a> {
19121914 return Some ( LexicalScopeBinding :: Item ( binding) ) ;
19131915 }
19141916 }
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 )
19281927 }
19291928
19301929 fn hygienic_lexical_parent (
@@ -2391,38 +2390,57 @@ impl<'a> Resolver<'a> {
23912390 . next ( )
23922391 . map_or ( false , |c| c. is_ascii_uppercase ( ) )
23932392 {
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 (
23992396 ident,
24002397 ValueNS ,
24012398 parent_scope,
24022399 None ,
24032400 path_span,
24042401 & ribs. unwrap ( ) [ ValueNS ] ,
24052402 ) {
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 ( ) )
24232413 }
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
24242440 }
2425- }
2441+ } else {
2442+ None
2443+ } ;
24262444
24272445 ( format ! ( "use of undeclared type `{}`" , ident) , suggestion)
24282446 } else {
@@ -2835,9 +2853,9 @@ impl<'a> Resolver<'a> {
28352853 }
28362854 }
28372855
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) ;
28412859 }
28422860
28432861 fn is_accessible_from ( & self , vis : ty:: Visibility , module : Module < ' a > ) -> bool {
0 commit comments