@@ -850,12 +850,65 @@ impl<'a> Resolver<'a> {
850
850
let resolution =
851
851
self . resolution ( module, key) . try_borrow_mut ( ) . map_err ( |_| ( Determined , Weak :: No ) ) ?; // This happens when there is a cycle of imports.
852
852
853
- if let Some ( binding) = resolution. binding && let Some ( path_span) = finalize {
853
+ if let Some ( path_span) = finalize {
854
+ let Some ( mut binding) = resolution. binding else {
855
+ return Err ( ( Determined , Weak :: No ) ) ;
856
+ } ;
857
+
854
858
if !restricted_shadowing && binding. expansion != LocalExpnId :: ROOT {
855
859
if let NameBindingKind :: Res ( _, true ) = binding. kind {
856
860
self . macro_expanded_macro_export_errors . insert ( ( path_span, binding. span ) ) ;
857
861
}
858
862
}
863
+
864
+ // If the primary binding is unusable, search further and return the shadowed glob
865
+ // binding if it exists. What we really want here is having two separate scopes in
866
+ // a module - one for non-globs and one for globs, but until that's done use this
867
+ // hack to avoid inconsistent resolution ICEs during import validation.
868
+ if let Some ( unusable_binding) = self . unusable_binding
869
+ && ptr:: eq ( binding, unusable_binding)
870
+ {
871
+ let Some ( shadowed) = resolution. shadowed_glob else {
872
+ return Err ( ( Determined , Weak :: No ) ) ;
873
+ } ;
874
+
875
+ if ptr:: eq ( shadowed, unusable_binding) {
876
+ return Err ( ( Determined , Weak :: No ) ) ;
877
+ }
878
+
879
+ binding = shadowed;
880
+ }
881
+
882
+ if !self . is_accessible_from ( binding. vis , parent_scope. module ) {
883
+ if self . last_import_segment {
884
+ return Err ( ( Determined , Weak :: No ) ) ;
885
+ } else {
886
+ self . privacy_errors . push ( PrivacyError {
887
+ ident,
888
+ binding,
889
+ dedup_span : path_span,
890
+ } ) ;
891
+ }
892
+ }
893
+
894
+ // Forbid expanded shadowing to avoid time travel.
895
+ if let Some ( shadowed_glob) = resolution. shadowed_glob
896
+ && restricted_shadowing
897
+ && binding. expansion != LocalExpnId :: ROOT
898
+ && binding. res ( ) != shadowed_glob. res ( )
899
+ {
900
+ self . ambiguity_errors . push ( AmbiguityError {
901
+ kind : AmbiguityKind :: GlobVsExpanded ,
902
+ ident,
903
+ b1 : binding,
904
+ b2 : shadowed_glob,
905
+ misc1 : AmbiguityErrorMisc :: None ,
906
+ misc2 : AmbiguityErrorMisc :: None ,
907
+ } ) ;
908
+ }
909
+
910
+ self . record_use ( ident, binding, restricted_shadowing) ;
911
+ return Ok ( binding) ;
859
912
}
860
913
861
914
let check_usable = |this : & mut Self , binding : & ' a NameBinding < ' a > | {
@@ -868,58 +921,6 @@ impl<'a> Resolver<'a> {
868
921
if usable { Ok ( binding) } else { Err ( ( Determined , Weak :: No ) ) }
869
922
} ;
870
923
871
- if let Some ( path_span) = finalize {
872
- return resolution
873
- . binding
874
- . and_then ( |binding| {
875
- // If the primary binding is unusable, search further and return the shadowed glob
876
- // binding if it exists. What we really want here is having two separate scopes in
877
- // a module - one for non-globs and one for globs, but until that's done use this
878
- // hack to avoid inconsistent resolution ICEs during import validation.
879
- if let Some ( unusable_binding) = self . unusable_binding {
880
- if ptr:: eq ( binding, unusable_binding) {
881
- return resolution. shadowed_glob ;
882
- }
883
- }
884
- Some ( binding)
885
- } )
886
- . ok_or ( ( Determined , Weak :: No ) )
887
- . and_then ( |binding| {
888
- if self . last_import_segment && check_usable ( self , binding) . is_err ( ) {
889
- Err ( ( Determined , Weak :: No ) )
890
- } else {
891
- self . record_use ( ident, binding, restricted_shadowing) ;
892
-
893
- if let Some ( shadowed_glob) = resolution. shadowed_glob {
894
- // Forbid expanded shadowing to avoid time travel.
895
- if restricted_shadowing
896
- && binding. expansion != LocalExpnId :: ROOT
897
- && binding. res ( ) != shadowed_glob. res ( )
898
- {
899
- self . ambiguity_errors . push ( AmbiguityError {
900
- kind : AmbiguityKind :: GlobVsExpanded ,
901
- ident,
902
- b1 : binding,
903
- b2 : shadowed_glob,
904
- misc1 : AmbiguityErrorMisc :: None ,
905
- misc2 : AmbiguityErrorMisc :: None ,
906
- } ) ;
907
- }
908
- }
909
-
910
- if !self . is_accessible_from ( binding. vis , parent_scope. module ) {
911
- self . privacy_errors . push ( PrivacyError {
912
- ident,
913
- binding,
914
- dedup_span : path_span,
915
- } ) ;
916
- }
917
-
918
- Ok ( binding)
919
- }
920
- } ) ;
921
- }
922
-
923
924
// Items and single imports are not shadowable, if we have one, then it's determined.
924
925
if let Some ( binding) = resolution. binding {
925
926
if !binding. is_glob_import ( ) {
0 commit comments