@@ -38,6 +38,12 @@ impl From<UsePrelude> for bool {
38
38
}
39
39
}
40
40
41
+ #[ derive( Debug , PartialEq ) ]
42
+ enum Shadowing {
43
+ Restricted ,
44
+ Unrestricted ,
45
+ }
46
+
41
47
impl < ' ra , ' tcx > Resolver < ' ra , ' tcx > {
42
48
/// A generic scope visitor.
43
49
/// Visits scopes in order to resolve some identifier in them or perform other actions.
@@ -349,7 +355,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
349
355
ident,
350
356
ns,
351
357
parent_scope,
352
- false ,
358
+ Shadowing :: Unrestricted ,
353
359
finalize. map ( |finalize| Finalize { used : Used :: Scope , ..finalize } ) ,
354
360
ignore_binding,
355
361
None ,
@@ -521,7 +527,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
521
527
ident,
522
528
ns,
523
529
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
+ } ,
525
535
finalize. map ( |finalize| Finalize { used : Used :: Scope , ..finalize } ) ,
526
536
ignore_binding,
527
537
ignore_import,
@@ -590,7 +600,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
590
600
ident,
591
601
ns,
592
602
parent_scope,
593
- false ,
603
+ Shadowing :: Unrestricted ,
594
604
None ,
595
605
ignore_binding,
596
606
ignore_import,
@@ -786,7 +796,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
786
796
ident,
787
797
ns,
788
798
adjusted_parent_scope,
789
- false ,
799
+ Shadowing :: Unrestricted ,
790
800
finalize,
791
801
ignore_binding,
792
802
ignore_import,
@@ -802,7 +812,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
802
812
ident : Ident ,
803
813
ns : Namespace ,
804
814
parent_scope : & ParentScope < ' ra > ,
805
- restricted_shadowing : bool ,
815
+ shadowing : Shadowing ,
806
816
finalize : Option < Finalize > ,
807
817
// This binding should be ignored during in-module resolution, so that we don't get
808
818
// "self-confirming" import resolutions during import validation and checking.
@@ -812,7 +822,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
812
822
let module = match module {
813
823
ModuleOrUniformRoot :: Module ( module) => module,
814
824
ModuleOrUniformRoot :: CrateRootAndExternPrelude => {
815
- assert ! ( !restricted_shadowing ) ;
825
+ assert_eq ! ( shadowing , Shadowing :: Unrestricted ) ;
816
826
let binding = self . early_resolve_ident_in_lexical_scope (
817
827
ident,
818
828
ScopeSet :: AbsolutePath ( ns) ,
@@ -825,7 +835,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
825
835
return binding. map_err ( |determinacy| ( determinacy, Weak :: No ) ) ;
826
836
}
827
837
ModuleOrUniformRoot :: ExternPrelude => {
828
- assert ! ( !restricted_shadowing ) ;
838
+ assert_eq ! ( shadowing , Shadowing :: Unrestricted ) ;
829
839
return if ns != TypeNS {
830
840
Err ( ( Determined , Weak :: No ) )
831
841
} else if let Some ( binding) = self . extern_prelude_get ( ident, finalize. is_some ( ) ) {
@@ -838,7 +848,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
838
848
} ;
839
849
}
840
850
ModuleOrUniformRoot :: CurrentScope => {
841
- assert ! ( !restricted_shadowing ) ;
851
+ assert_eq ! ( shadowing , Shadowing :: Unrestricted ) ;
842
852
if ns == TypeNS {
843
853
if ident. name == kw:: Crate || ident. name == kw:: DollarCrate {
844
854
let module = self . resolve_crate_root ( ident) ;
@@ -897,7 +907,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
897
907
898
908
// Forbid expanded shadowing to avoid time travel.
899
909
if let Some ( shadowed_glob) = resolution. shadowed_glob
900
- && restricted_shadowing
910
+ && shadowing == Shadowing :: Restricted
901
911
&& binding. expansion != LocalExpnId :: ROOT
902
912
&& binding. res ( ) != shadowed_glob. res ( )
903
913
{
@@ -912,7 +922,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
912
922
} ) ;
913
923
}
914
924
915
- if !restricted_shadowing
925
+ if shadowing == Shadowing :: Unrestricted
916
926
&& binding. expansion != LocalExpnId :: ROOT
917
927
&& let NameBindingKind :: Import { import, .. } = binding. kind
918
928
&& matches ! ( import. kind, ImportKind :: MacroExport )
@@ -1024,7 +1034,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1024
1034
// and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
1025
1035
// shadowing is enabled, see `macro_expanded_macro_export_errors`).
1026
1036
if let Some ( binding) = binding {
1027
- if binding. determined ( ) || ns == MacroNS || restricted_shadowing {
1037
+ if binding. determined ( ) || ns == MacroNS || shadowing == Shadowing :: Restricted {
1028
1038
return check_usable ( self , binding) ;
1029
1039
} else {
1030
1040
return Err ( ( Undetermined , Weak :: No ) ) ;
@@ -1076,7 +1086,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1076
1086
ident,
1077
1087
ns,
1078
1088
adjusted_parent_scope,
1079
- false ,
1089
+ Shadowing :: Unrestricted ,
1080
1090
None ,
1081
1091
ignore_binding,
1082
1092
ignore_import,
0 commit comments