@@ -53,7 +53,7 @@ enum SideEffectBindings<'ra> {
5353 import_bindings : PerNS < Option < Option < NameBinding < ' ra > > > > ,
5454 } ,
5555 Glob {
56- import_bindings : Vec < ( NameBinding < ' ra > , BindingKey , bool /* warn_ambiguity */ ) > ,
56+ import_bindings : Vec < ( NameBinding < ' ra > , BindingKey ) > ,
5757 } ,
5858}
5959
@@ -607,17 +607,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
607607 !self . assert_speculative,
608608 "`commit_import_resolutions` should not be called during speculative resolution"
609609 ) ;
610- self . determined_imports . reserve ( self . determined_imports . len ( ) ) ;
611610 for ( import, side_effect) in import_resolutions. iter ( ) {
612- self . determined_imports . push ( * import) ;
613611 let SideEffect { imported_module, .. } = side_effect;
614612 import. imported_module . set_unchecked ( Some ( * imported_module) ) ;
615613
616- if import. is_glob ( )
617- && let ModuleOrUniformRoot :: Module ( module) = imported_module
618- && import. parent_scope . module != * module
619- {
620- module. glob_importers . borrow_mut ( self ) . push ( * import) ;
614+ if import. is_glob ( ) {
615+ let ModuleOrUniformRoot :: Module ( module) = imported_module else {
616+ self . dcx ( ) . emit_err ( CannotGlobImportAllCrates { span : import. span } ) ;
617+ continue ;
618+ } ;
619+ if import. parent_scope . module != * module {
620+ module. glob_importers . borrow_mut_unchecked ( ) . push ( * import) ;
621+ }
621622 }
622623 }
623624
@@ -668,7 +669,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
668669 }
669670 ( ImportKind :: Glob { id, .. } , SideEffectBindings :: Glob { import_bindings } ) => {
670671 let ModuleOrUniformRoot :: Module ( module) = imported_module else {
671- self . dcx ( ) . emit_err ( CannotGlobImportAllCrates { span : import. span } ) ;
672672 continue ;
673673 } ;
674674
@@ -683,12 +683,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
683683 . emit ( ) ;
684684 }
685685
686- for ( binding, key, warn_ambiguity) in import_bindings {
686+ for ( binding, key) in import_bindings {
687+ let imported_binding = self . import ( binding, import) ;
688+ let warn_ambiguity = self
689+ . resolution ( import. parent_scope . module , key)
690+ . and_then ( |r| r. binding ( ) )
691+ . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
687692 let _ = self . try_define_local (
688693 parent,
689694 key. ident . 0 ,
690695 key. ns ,
691- binding ,
696+ imported_binding ,
692697 warn_ambiguity,
693698 ) ;
694699 }
@@ -970,7 +975,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
970975 ///
971976 /// Meanwhile, if resolution is successful, the side effect of the resolution is returned.
972977 fn resolve_import < ' r > (
973- self : & mut CmResolver < ' r , ' ra , ' tcx > ,
978+ mut self : CmResolver < ' r , ' ra , ' tcx > ,
974979 import : Import < ' ra > ,
975980 ) -> ( Option < SideEffect < ' ra > > , usize ) {
976981 debug ! (
@@ -1015,12 +1020,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10151020
10161021 let mut import_bindings = PerNS :: default ( ) ;
10171022 let mut indeterminate_count = 0 ;
1018- self . reborrow ( ) . per_ns_cm ( |this, ns| {
1023+
1024+ // HACK: Use array of namespaces in the same order as `per_ns_mut`.
1025+ // We can't use `per_ns_cm` because of the invariance on CmResolver (RefOrMut).
1026+ for ns in [ TypeNS , ValueNS , MacroNS ] {
10191027 if !type_ns_only || ns == TypeNS {
10201028 if bindings[ ns] . get ( ) != PendingBinding :: Pending {
1021- return ;
1029+ continue ;
10221030 } ;
1023- let binding_result = this . reborrow ( ) . maybe_resolve_ident_in_module (
1031+ let binding_result = self . reborrow ( ) . maybe_resolve_ident_in_module (
10241032 module,
10251033 source,
10261034 ns,
@@ -1030,7 +1038,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10301038 let pending_binding = match binding_result {
10311039 Ok ( binding) => {
10321040 // We need the `target`, `source` can be extracted.
1033- let imported_binding = this . import ( binding, import) ;
1041+ let imported_binding = self . import ( binding, import) ;
10341042 Some ( Some ( imported_binding) )
10351043 }
10361044 Err ( Determinacy :: Determined ) => Some ( None ) ,
@@ -1042,8 +1050,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10421050 // FIXME(batched): Will be fixed in batched import resolution.
10431051 import_bindings[ ns] = pending_binding;
10441052 }
1045- } ) ;
1046-
1053+ }
10471054 (
10481055 Some ( SideEffect {
10491056 imported_module : module,
@@ -1593,47 +1600,40 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15931600 false
15941601 }
15951602
1596- fn resolve_glob_import < ' r > (
1597- self : & mut CmResolver < ' r , ' ra , ' tcx > ,
1603+ fn resolve_glob_import (
1604+ & self ,
15981605 import : Import < ' ra > ,
15991606 imported_module : ModuleOrUniformRoot < ' ra > ,
16001607 ) -> SideEffectBindings < ' ra > {
1601- // This function is only called for glob imports.
1602- let ImportKind :: Glob { .. } = import. kind else { unreachable ! ( ) } ;
1608+ match imported_module {
1609+ ModuleOrUniformRoot :: Module ( module) if module != import. parent_scope . module => {
1610+ let import_bindings = self
1611+ . resolutions ( module)
1612+ . borrow ( )
1613+ . iter ( )
1614+ . filter_map ( |( key, resolution) | {
1615+ let binding = resolution. borrow ( ) . binding ( ) ?;
1616+ let mut key = * key;
1617+ let scope = match key
1618+ . ident
1619+ . 0
1620+ . span
1621+ . reverse_glob_adjust ( module. expansion , import. span )
1622+ {
1623+ Some ( Some ( def) ) => self . expn_def_scope ( def) ,
1624+ Some ( None ) => import. parent_scope . module ,
1625+ None => return None ,
1626+ } ;
1627+ self . is_accessible_from ( binding. vis , scope) . then ( || ( binding, key) )
1628+ } )
1629+ . collect :: < Vec < _ > > ( ) ;
16031630
1604- let ModuleOrUniformRoot :: Module ( module) = imported_module else {
1605- return SideEffectBindings :: None ;
1606- } ;
1631+ SideEffectBindings :: Glob { import_bindings }
1632+ }
16071633
1608- if module == import . parent_scope . module {
1609- return SideEffectBindings :: None ;
1634+ // Errors are reported in `commit_imports_resolutions`
1635+ _ => SideEffectBindings :: None ,
16101636 }
1611-
1612- let import_bindings = self
1613- . resolutions ( module)
1614- . borrow ( )
1615- . iter ( )
1616- . filter_map ( |( key, resolution) | {
1617- let binding = resolution. borrow ( ) . binding ( ) ?;
1618- let mut key = * key;
1619- let scope =
1620- match key. ident . 0 . span . reverse_glob_adjust ( module. expansion , import. span ) {
1621- Some ( Some ( def) ) => self . expn_def_scope ( def) ,
1622- Some ( None ) => import. parent_scope . module ,
1623- None => return None ,
1624- } ;
1625- self . is_accessible_from ( binding. vis , scope) . then ( || {
1626- let imported_binding = self . import ( binding, import) ;
1627- let warn_ambiguity = self
1628- . resolution ( import. parent_scope . module , key)
1629- . and_then ( |r| r. binding ( ) )
1630- . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
1631- ( imported_binding, key, warn_ambiguity)
1632- } )
1633- } )
1634- . collect :: < Vec < _ > > ( ) ;
1635-
1636- SideEffectBindings :: Glob { import_bindings }
16371637 }
16381638
16391639 // Miscellaneous post-processing, including recording re-exports,
0 commit comments