@@ -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.
@@ -349,7 +355,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
349355 ident,
350356 ns,
351357 parent_scope,
352- false ,
358+ Shadowing :: Unrestricted ,
353359 finalize. map ( |finalize| Finalize { used : Used :: Scope , ..finalize } ) ,
354360 ignore_binding,
355361 None ,
@@ -521,7 +527,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
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,7 +600,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
590600 ident,
591601 ns,
592602 parent_scope,
593- false ,
603+ Shadowing :: Unrestricted ,
594604 None ,
595605 ignore_binding,
596606 ignore_import,
@@ -786,7 +796,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
786796 ident,
787797 ns,
788798 adjusted_parent_scope,
789- false ,
799+ Shadowing :: Unrestricted ,
790800 finalize,
791801 ignore_binding,
792802 ignore_import,
@@ -802,7 +812,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
802812 ident : Ident ,
803813 ns : Namespace ,
804814 parent_scope : & ParentScope < ' ra > ,
805- restricted_shadowing : bool ,
815+ shadowing : Shadowing ,
806816 finalize : Option < Finalize > ,
807817 // This binding should be ignored during in-module resolution, so that we don't get
808818 // "self-confirming" import resolutions during import validation and checking.
@@ -812,7 +822,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
812822 let module = match module {
813823 ModuleOrUniformRoot :: Module ( module) => module,
814824 ModuleOrUniformRoot :: CrateRootAndExternPrelude => {
815- assert ! ( !restricted_shadowing ) ;
825+ assert_eq ! ( shadowing , Shadowing :: Unrestricted ) ;
816826 let binding = self . early_resolve_ident_in_lexical_scope (
817827 ident,
818828 ScopeSet :: AbsolutePath ( ns) ,
@@ -825,7 +835,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
825835 return binding. map_err ( |determinacy| ( determinacy, Weak :: No ) ) ;
826836 }
827837 ModuleOrUniformRoot :: ExternPrelude => {
828- assert ! ( !restricted_shadowing ) ;
838+ assert_eq ! ( shadowing , Shadowing :: Unrestricted ) ;
829839 return if ns != TypeNS {
830840 Err ( ( Determined , Weak :: No ) )
831841 } else if let Some ( binding) = self . extern_prelude_get ( ident, finalize. is_some ( ) ) {
@@ -838,7 +848,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
838848 } ;
839849 }
840850 ModuleOrUniformRoot :: CurrentScope => {
841- assert ! ( !restricted_shadowing ) ;
851+ assert_eq ! ( shadowing , Shadowing :: Unrestricted ) ;
842852 if ns == TypeNS {
843853 if ident. name == kw:: Crate || ident. name == kw:: DollarCrate {
844854 let module = self . resolve_crate_root ( ident) ;
@@ -897,7 +907,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
897907
898908 // Forbid expanded shadowing to avoid time travel.
899909 if let Some ( shadowed_glob) = resolution. shadowed_glob
900- && restricted_shadowing
910+ && shadowing == Shadowing :: Restricted
901911 && binding. expansion != LocalExpnId :: ROOT
902912 && binding. res ( ) != shadowed_glob. res ( )
903913 {
@@ -912,7 +922,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
912922 } ) ;
913923 }
914924
915- if !restricted_shadowing
925+ if shadowing == Shadowing :: Unrestricted
916926 && binding. expansion != LocalExpnId :: ROOT
917927 && let NameBindingKind :: Import { import, .. } = binding. kind
918928 && matches ! ( import. kind, ImportKind :: MacroExport )
@@ -1024,7 +1034,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10241034 // and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
10251035 // shadowing is enabled, see `macro_expanded_macro_export_errors`).
10261036 if let Some ( binding) = binding {
1027- if binding. determined ( ) || ns == MacroNS || restricted_shadowing {
1037+ if binding. determined ( ) || ns == MacroNS || shadowing == Shadowing :: Restricted {
10281038 return check_usable ( self , binding) ;
10291039 } else {
10301040 return Err ( ( Undetermined , Weak :: No ) ) ;
@@ -1076,7 +1086,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10761086 ident,
10771087 ns,
10781088 adjusted_parent_scope,
1079- false ,
1089+ Shadowing :: Unrestricted ,
10801090 None ,
10811091 ignore_binding,
10821092 ignore_import,
0 commit comments