@@ -38,6 +38,12 @@ impl From<UsePrelude> for bool {
3838    } 
3939} 
4040
41+ #[ derive( Debug ,  PartialEq ) ]  
42+ enum  Shadowing  { 
43+     Restricted , 
44+     Unrestricted , 
45+ } 
46+ 
4147impl < ' ra ,  ' tcx >  Resolver < ' ra ,  ' tcx >  { 
4248    /// A generic scope visitor. 
4349/// Visits scopes in order to resolve some identifier in them or perform other actions. 
@@ -311,13 +317,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
311317
312318        // Walk backwards up the ribs in scope. 
313319        let  mut  module = self . graph_root ; 
314-         for  i  in  ( 0 .. ribs. len ( ) ) . rev ( )  { 
315-             debug ! ( "walk rib\n {:?}" ,  ribs [ i ] . bindings) ; 
320+         for  ( i ,  rib )   in  ribs. iter ( ) . enumerate ( ) . rev ( )  { 
321+             debug ! ( "walk rib\n {:?}" ,  rib . bindings) ; 
316322            // Use the rib kind to determine whether we are resolving parameters 
317323            // (macro 2.0 hygiene) or local variables (`macro_rules` hygiene). 
318-             let  rib_ident = if  ribs[ i] . kind . contains_params ( )  {  normalized_ident }  else  {  ident } ; 
319-             if  let  Some ( ( original_rib_ident_def,  res) )  = ribs[ i] . bindings . get_key_value ( & rib_ident) 
320-             { 
324+             let  rib_ident = if  rib. kind . contains_params ( )  {  normalized_ident }  else  {  ident } ; 
325+             if  let  Some ( ( original_rib_ident_def,  res) )  = rib. bindings . get_key_value ( & rib_ident)  { 
321326                // The ident resolves to a type parameter or local variable. 
322327                return  Some ( LexicalScopeBinding :: Res ( self . validate_res_from_ribs ( 
323328                    i, 
@@ -329,7 +334,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
329334                ) ) ) ; 
330335            } 
331336
332-             module = match  ribs [ i ] . kind  { 
337+             module = match  rib . kind  { 
333338                RibKind :: Module ( module)  => module, 
334339                RibKind :: MacroDefinition ( def)  if  def == self . macro_def ( ident. span . ctxt ( ) )  => { 
335340                    // If an invocation of this macro created `ident`, give up on `ident` 
@@ -350,6 +355,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
350355                ident, 
351356                ns, 
352357                parent_scope, 
358+                 Shadowing :: Unrestricted , 
353359                finalize. map ( |finalize| Finalize  {  used :  Used :: Scope ,  ..finalize } ) , 
354360                ignore_binding, 
355361                None , 
@@ -494,7 +500,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
494500                    Scope :: CrateRoot  => { 
495501                        let  root_ident = Ident :: new ( kw:: PathRoot ,  ident. span ) ; 
496502                        let  root_module = this. resolve_crate_root ( root_ident) ; 
497-                         let  binding = this. resolve_ident_in_module_ext ( 
503+                         let  binding = this. resolve_ident_in_module ( 
498504                            ModuleOrUniformRoot :: Module ( root_module) , 
499505                            ident, 
500506                            ns, 
@@ -516,12 +522,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
516522                    } 
517523                    Scope :: Module ( module,  derive_fallback_lint_id)  => { 
518524                        let  adjusted_parent_scope = & ParentScope  {  module,  ..* parent_scope } ; 
519-                         let  binding = this. resolve_ident_in_module_unadjusted_ext ( 
525+                         let  binding = this. resolve_ident_in_module_unadjusted ( 
520526                            ModuleOrUniformRoot :: Module ( module) , 
521527                            ident, 
522528                            ns, 
523529                            adjusted_parent_scope, 
524-                             !matches ! ( scope_set,  ScopeSet :: Late ( ..) ) , 
530+                             if  matches ! ( scope_set,  ScopeSet :: Late ( ..) )  { 
531+                                 Shadowing :: Unrestricted 
532+                             }  else  { 
533+                                 Shadowing :: Restricted 
534+                             } , 
525535                            finalize. map ( |finalize| Finalize  {  used :  Used :: Scope ,  ..finalize } ) , 
526536                            ignore_binding, 
527537                            ignore_import, 
@@ -590,6 +600,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
590600                                ident, 
591601                                ns, 
592602                                parent_scope, 
603+                                 Shadowing :: Unrestricted , 
593604                                None , 
594605                                ignore_binding, 
595606                                ignore_import, 
@@ -748,35 +759,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
748759        parent_scope :  & ParentScope < ' ra > , 
749760        ignore_import :  Option < Import < ' ra > > , 
750761    )  -> Result < NameBinding < ' ra > ,  Determinacy >  { 
751-         self . resolve_ident_in_module_ext ( module,  ident,  ns,  parent_scope,  None ,  None ,  ignore_import) 
762+         self . resolve_ident_in_module ( module,  ident,  ns,  parent_scope,  None ,  None ,  ignore_import) 
752763            . map_err ( |( determinacy,  _) | determinacy) 
753764    } 
754765
755766    #[ instrument( level = "debug" ,  skip( self ) ) ]  
756767    pub ( crate )  fn  resolve_ident_in_module ( 
757-         & mut  self , 
758-         module :  ModuleOrUniformRoot < ' ra > , 
759-         ident :  Ident , 
760-         ns :  Namespace , 
761-         parent_scope :  & ParentScope < ' ra > , 
762-         finalize :  Option < Finalize > , 
763-         ignore_binding :  Option < NameBinding < ' ra > > , 
764-         ignore_import :  Option < Import < ' ra > > , 
765-     )  -> Result < NameBinding < ' ra > ,  Determinacy >  { 
766-         self . resolve_ident_in_module_ext ( 
767-             module, 
768-             ident, 
769-             ns, 
770-             parent_scope, 
771-             finalize, 
772-             ignore_binding, 
773-             ignore_import, 
774-         ) 
775-         . map_err ( |( determinacy,  _) | determinacy) 
776-     } 
777- 
778-     #[ instrument( level = "debug" ,  skip( self ) ) ]  
779-     fn  resolve_ident_in_module_ext ( 
780768        & mut  self , 
781769        module :  ModuleOrUniformRoot < ' ra > , 
782770        mut  ident :  Ident , 
@@ -803,52 +791,28 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
803791                // No adjustments 
804792            } 
805793        } 
806-         self . resolve_ident_in_module_unadjusted_ext ( 
794+         self . resolve_ident_in_module_unadjusted ( 
807795            module, 
808796            ident, 
809797            ns, 
810798            adjusted_parent_scope, 
811-             false , 
799+             Shadowing :: Unrestricted , 
812800            finalize, 
813801            ignore_binding, 
814802            ignore_import, 
815803        ) 
816804    } 
817805
818-     #[ instrument( level = "debug" ,  skip( self ) ) ]  
819-     fn  resolve_ident_in_module_unadjusted ( 
820-         & mut  self , 
821-         module :  ModuleOrUniformRoot < ' ra > , 
822-         ident :  Ident , 
823-         ns :  Namespace , 
824-         parent_scope :  & ParentScope < ' ra > , 
825-         finalize :  Option < Finalize > , 
826-         ignore_binding :  Option < NameBinding < ' ra > > , 
827-         ignore_import :  Option < Import < ' ra > > , 
828-     )  -> Result < NameBinding < ' ra > ,  Determinacy >  { 
829-         self . resolve_ident_in_module_unadjusted_ext ( 
830-             module, 
831-             ident, 
832-             ns, 
833-             parent_scope, 
834-             false , 
835-             finalize, 
836-             ignore_binding, 
837-             ignore_import, 
838-         ) 
839-         . map_err ( |( determinacy,  _) | determinacy) 
840-     } 
841- 
842806    /// Attempts to resolve `ident` in namespaces `ns` of `module`. 
843807/// Invariant: if `finalize` is `Some`, expansion and import resolution must be complete. 
844808#[ instrument( level = "debug" ,  skip( self ) ) ]  
845-     fn  resolve_ident_in_module_unadjusted_ext ( 
809+     fn  resolve_ident_in_module_unadjusted ( 
846810        & mut  self , 
847811        module :  ModuleOrUniformRoot < ' ra > , 
848812        ident :  Ident , 
849813        ns :  Namespace , 
850814        parent_scope :  & ParentScope < ' ra > , 
851-         restricted_shadowing :   bool , 
815+         shadowing :   Shadowing , 
852816        finalize :  Option < Finalize > , 
853817        // This binding should be ignored during in-module resolution, so that we don't get 
854818        // "self-confirming" import resolutions during import validation and checking. 
@@ -858,7 +822,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
858822        let  module = match  module { 
859823            ModuleOrUniformRoot :: Module ( module)  => module, 
860824            ModuleOrUniformRoot :: CrateRootAndExternPrelude  => { 
861-                 assert ! ( !restricted_shadowing ) ; 
825+                 assert_eq ! ( shadowing ,   Shadowing :: Unrestricted ) ; 
862826                let  binding = self . early_resolve_ident_in_lexical_scope ( 
863827                    ident, 
864828                    ScopeSet :: AbsolutePath ( ns) , 
@@ -871,7 +835,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
871835                return  binding. map_err ( |determinacy| ( determinacy,  Weak :: No ) ) ; 
872836            } 
873837            ModuleOrUniformRoot :: ExternPrelude  => { 
874-                 assert ! ( !restricted_shadowing ) ; 
838+                 assert_eq ! ( shadowing ,   Shadowing :: Unrestricted ) ; 
875839                return  if  ns != TypeNS  { 
876840                    Err ( ( Determined ,  Weak :: No ) ) 
877841                }  else  if  let  Some ( binding)  = self . extern_prelude_get ( ident,  finalize. is_some ( ) )  { 
@@ -884,7 +848,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
884848                } ; 
885849            } 
886850            ModuleOrUniformRoot :: CurrentScope  => { 
887-                 assert ! ( !restricted_shadowing ) ; 
851+                 assert_eq ! ( shadowing ,   Shadowing :: Unrestricted ) ; 
888852                if  ns == TypeNS  { 
889853                    if  ident. name  == kw:: Crate  || ident. name  == kw:: DollarCrate  { 
890854                        let  module = self . resolve_crate_root ( ident) ; 
@@ -943,7 +907,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
943907
944908            // Forbid expanded shadowing to avoid time travel. 
945909            if  let  Some ( shadowed_glob)  = resolution. shadowed_glob 
946-                 && restricted_shadowing 
910+                 && shadowing ==  Shadowing :: Restricted 
947911                && binding. expansion  != LocalExpnId :: ROOT 
948912                && binding. res ( )  != shadowed_glob. res ( ) 
949913            { 
@@ -958,7 +922,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
958922                } ) ; 
959923            } 
960924
961-             if  !restricted_shadowing 
925+             if  shadowing ==  Shadowing :: Unrestricted 
962926                && binding. expansion  != LocalExpnId :: ROOT 
963927                && let  NameBindingKind :: Import  {  import,  .. }  = binding. kind 
964928                && matches ! ( import. kind,  ImportKind :: MacroExport ) 
@@ -1047,13 +1011,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10471011                ignore_binding, 
10481012                ignore_import, 
10491013            )  { 
1050-                 Err ( Determined )  => continue , 
1014+                 Err ( ( Determined ,  _ ) )  => continue , 
10511015                Ok ( binding) 
10521016                    if  !self . is_accessible_from ( binding. vis ,  single_import. parent_scope . module )  =>
10531017                { 
10541018                    continue ; 
10551019                } 
1056-                 Ok ( _)  | Err ( Undetermined )  => return  Err ( ( Undetermined ,  Weak :: No ) ) , 
1020+                 Ok ( _)  | Err ( ( Undetermined ,  _ ) )  => return  Err ( ( Undetermined ,  Weak :: No ) ) , 
10571021            } 
10581022        } 
10591023
@@ -1070,7 +1034,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10701034        // and prohibit access to macro-expanded `macro_export` macros instead (unless restricted 
10711035        // shadowing is enabled, see `macro_expanded_macro_export_errors`). 
10721036        if  let  Some ( binding)  = binding { 
1073-             if  binding. determined ( )  || ns == MacroNS  || restricted_shadowing  { 
1037+             if  binding. determined ( )  || ns == MacroNS  || shadowing ==  Shadowing :: Restricted  { 
10741038                return  check_usable ( self ,  binding) ; 
10751039            }  else  { 
10761040                return  Err ( ( Undetermined ,  Weak :: No ) ) ; 
@@ -1122,19 +1086,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11221086                ident, 
11231087                ns, 
11241088                adjusted_parent_scope, 
1089+                 Shadowing :: Unrestricted , 
11251090                None , 
11261091                ignore_binding, 
11271092                ignore_import, 
11281093            ) ; 
11291094
11301095            match  result { 
1131-                 Err ( Determined )  => continue , 
1096+                 Err ( ( Determined ,  _ ) )  => continue , 
11321097                Ok ( binding) 
11331098                    if  !self . is_accessible_from ( binding. vis ,  glob_import. parent_scope . module )  =>
11341099                { 
11351100                    continue ; 
11361101                } 
1137-                 Ok ( _)  | Err ( Undetermined )  => return  Err ( ( Undetermined ,  Weak :: Yes ) ) , 
1102+                 Ok ( _)  | Err ( ( Undetermined ,  _ ) )  => return  Err ( ( Undetermined ,  Weak :: Yes ) ) , 
11381103            } 
11391104        } 
11401105
@@ -1200,7 +1165,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12001165                            // Still doesn't deal with upvars 
12011166                            if  let  Some ( span)  = finalize { 
12021167                                let  ( span,  resolution_error)  = match  item { 
1203-                                     None  if  rib_ident. as_str ( )  == "self"  => ( span,  LowercaseSelf ) , 
1168+                                     None  if  rib_ident. name  == kw:: SelfLower  => { 
1169+                                         ( span,  LowercaseSelf ) 
1170+                                     } 
12041171                                    None  => { 
12051172                                        // If we have a `let name = expr;`, we have the span for 
12061173                                        // `name` and use that to see if it is followed by a type 
@@ -1563,6 +1530,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15631530                    ignore_binding, 
15641531                    ignore_import, 
15651532                ) 
1533+                 . map_err ( |( determinacy,  _) | determinacy) 
15661534            }  else  if  let  Some ( ribs)  = ribs
15671535                && let  Some ( TypeNS  | ValueNS )  = opt_ns
15681536            { 
0 commit comments