@@ -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
@@ -605,17 +605,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
605605 !self . assert_speculative,
606606 "`commit_import_resolutions` should not be called during speculative resolution"
607607 ) ;
608- self . determined_imports . reserve ( self . determined_imports . len ( ) ) ;
609608 for ( import, side_effect) in import_resolutions. iter ( ) {
610- self . determined_imports . push ( * import) ;
611609 let SideEffect { imported_module, .. } = side_effect;
612610 import. imported_module . set_unchecked ( Some ( * imported_module) ) ;
613611
614- if import. is_glob ( )
615- && let ModuleOrUniformRoot :: Module ( module) = imported_module
616- && import. parent_scope . module != * module
617- {
618- module. glob_importers . borrow_mut ( self ) . push ( * import) ;
612+ if import. is_glob ( ) {
613+ let ModuleOrUniformRoot :: Module ( module) = imported_module else {
614+ self . dcx ( ) . emit_err ( CannotGlobImportAllCrates { span : import. span } ) ;
615+ continue ;
616+ } ;
617+ if import. parent_scope . module != * module {
618+ module. glob_importers . borrow_mut_unchecked ( ) . push ( * import) ;
619+ }
619620 }
620621 }
621622
@@ -666,7 +667,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
666667 }
667668 ( ImportKind :: Glob { id, .. } , SideEffectBindings :: Glob { import_bindings } ) => {
668669 let ModuleOrUniformRoot :: Module ( module) = imported_module else {
669- self . dcx ( ) . emit_err ( CannotGlobImportAllCrates { span : import. span } ) ;
670670 continue ;
671671 } ;
672672
@@ -681,12 +681,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
681681 . emit ( ) ;
682682 }
683683
684- for ( binding, key, warn_ambiguity) in import_bindings {
684+ for ( binding, key) in import_bindings {
685+ let imported_binding = self . import ( binding, import) ;
686+ let warn_ambiguity = self
687+ . resolution ( import. parent_scope . module , key)
688+ . and_then ( |r| r. binding ( ) )
689+ . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
685690 let _ = self . try_define_local (
686691 parent,
687692 key. ident . 0 ,
688693 key. ns ,
689- binding ,
694+ imported_binding ,
690695 warn_ambiguity,
691696 ) ;
692697 }
@@ -971,7 +976,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
971976 ///
972977 /// Meanwhile, if resolution is successful, the side effect of the resolution is returned.
973978 fn resolve_import < ' r > (
974- self : & mut CmResolver < ' r , ' ra , ' tcx > ,
979+ mut self : CmResolver < ' r , ' ra , ' tcx > ,
975980 import : Import < ' ra > ,
976981 ) -> ( Option < SideEffect < ' ra > > , usize ) {
977982 debug ! (
@@ -1016,12 +1021,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10161021
10171022 let mut import_bindings = PerNS :: default ( ) ;
10181023 let mut indeterminate_count = 0 ;
1019- self . reborrow ( ) . per_ns_cm ( |this, ns| {
1024+
1025+ // HACK: Use array of namespaces in the same order as `per_ns_mut`.
1026+ // We can't use `per_ns_cm` because of the invariance on CmResolver (RefOrMut).
1027+ for ns in [ TypeNS , ValueNS , MacroNS ] {
10201028 if !type_ns_only || ns == TypeNS {
10211029 if bindings[ ns] . get ( ) != PendingBinding :: Pending {
1022- return ;
1030+ continue ;
10231031 } ;
1024- let binding_result = this . reborrow ( ) . maybe_resolve_ident_in_module (
1032+ let binding_result = self . reborrow ( ) . maybe_resolve_ident_in_module (
10251033 module,
10261034 source,
10271035 ns,
@@ -1031,7 +1039,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10311039 let pending_binding = match binding_result {
10321040 Ok ( binding) => {
10331041 // We need the `target`, `source` can be extracted.
1034- let imported_binding = this . import ( binding, import) ;
1042+ let imported_binding = self . import ( binding, import) ;
10351043 Some ( Some ( imported_binding) )
10361044 }
10371045 Err ( Determinacy :: Determined ) => Some ( None ) ,
@@ -1043,8 +1051,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10431051 // FIXME(batched): Will be fixed in batched import resolution.
10441052 import_bindings[ ns] = pending_binding;
10451053 }
1046- } ) ;
1047-
1054+ }
10481055 (
10491056 Some ( SideEffect {
10501057 imported_module : module,
@@ -1594,47 +1601,40 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15941601 false
15951602 }
15961603
1597- fn resolve_glob_import < ' r > (
1598- self : & mut CmResolver < ' r , ' ra , ' tcx > ,
1604+ fn resolve_glob_import (
1605+ & self ,
15991606 import : Import < ' ra > ,
16001607 imported_module : ModuleOrUniformRoot < ' ra > ,
16011608 ) -> SideEffectBindings < ' ra > {
1602- // This function is only called for glob imports.
1603- let ImportKind :: Glob { .. } = import. kind else { unreachable ! ( ) } ;
1609+ match imported_module {
1610+ ModuleOrUniformRoot :: Module ( module) if module != import. parent_scope . module => {
1611+ let import_bindings = self
1612+ . resolutions ( module)
1613+ . borrow ( )
1614+ . iter ( )
1615+ . filter_map ( |( key, resolution) | {
1616+ let binding = resolution. borrow ( ) . binding ( ) ?;
1617+ let mut key = * key;
1618+ let scope = match key
1619+ . ident
1620+ . 0
1621+ . span
1622+ . reverse_glob_adjust ( module. expansion , import. span )
1623+ {
1624+ Some ( Some ( def) ) => self . expn_def_scope ( def) ,
1625+ Some ( None ) => import. parent_scope . module ,
1626+ None => return None ,
1627+ } ;
1628+ self . is_accessible_from ( binding. vis , scope) . then ( || ( binding, key) )
1629+ } )
1630+ . collect :: < Vec < _ > > ( ) ;
16041631
1605- let ModuleOrUniformRoot :: Module ( module) = imported_module else {
1606- return SideEffectBindings :: None ;
1607- } ;
1632+ SideEffectBindings :: Glob { import_bindings }
1633+ }
16081634
1609- if module == import . parent_scope . module {
1610- return SideEffectBindings :: None ;
1635+ // Errors are reported in `commit_imports_resolutions`
1636+ _ => SideEffectBindings :: None ,
16111637 }
1612-
1613- let import_bindings = self
1614- . resolutions ( module)
1615- . borrow ( )
1616- . iter ( )
1617- . filter_map ( |( key, resolution) | {
1618- let binding = resolution. borrow ( ) . binding ( ) ?;
1619- let mut key = * key;
1620- let scope =
1621- match key. ident . 0 . span . reverse_glob_adjust ( module. expansion , import. span ) {
1622- Some ( Some ( def) ) => self . expn_def_scope ( def) ,
1623- Some ( None ) => import. parent_scope . module ,
1624- None => return None ,
1625- } ;
1626- self . is_accessible_from ( binding. vis , scope) . then ( || {
1627- let imported_binding = self . import ( binding, import) ;
1628- let warn_ambiguity = self
1629- . resolution ( import. parent_scope . module , key)
1630- . and_then ( |r| r. binding ( ) )
1631- . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
1632- ( imported_binding, key, warn_ambiguity)
1633- } )
1634- } )
1635- . collect :: < Vec < _ > > ( ) ;
1636-
1637- SideEffectBindings :: Glob { import_bindings }
16381638 }
16391639
16401640 // Miscellaneous post-processing, including recording re-exports,
0 commit comments