@@ -5,7 +5,7 @@ use std::mem;
55use std:: ops:: Deref ;
66
77use rustc_ast:: NodeId ;
8- use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
8+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
99use rustc_data_structures:: intern:: Interned ;
1010use rustc_errors:: codes:: * ;
1111use rustc_errors:: { Applicability , MultiSpan , pluralize, struct_span_code_err} ;
@@ -47,16 +47,20 @@ pub(crate) struct ImportResolver<'r, 'ra, 'tcx> {
4747 batch : Vec < Import < ' ra > > , // a.k.a. indeterminate_imports, also treated as output
4848
4949 // outputs
50+ prelude : Option < Module < ' ra > > ,
5051 determined_imports : Vec < Import < ' ra > > ,
51- glob_import_outputs : Vec < ( Module < ' ra > , BindingKey , NameBinding < ' ra > , bool ) > ,
52+ module_glob_importers : FxIndexMap < Module < ' ra > , Vec < Import < ' ra > > > ,
53+ glob_import_bindings : Vec < ( Module < ' ra > , BindingKey , NameBinding < ' ra > , bool ) > ,
5254 glob_res_outputs : Vec < ( NodeId , PartialRes ) > ,
5355 import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
5456}
5557
5658struct ImportResolutionOutputs < ' ra > {
59+ prelude : Option < Module < ' ra > > ,
5760 indeterminate_imports : Vec < Import < ' ra > > ,
5861 determined_imports : Vec < Import < ' ra > > ,
59- glob_import_outputs : Vec < ( Module < ' ra > , BindingKey , NameBinding < ' ra > , bool ) > ,
62+ module_glob_importers : FxIndexMap < Module < ' ra > , Vec < Import < ' ra > > > ,
63+ glob_import_bindings : Vec < ( Module < ' ra > , BindingKey , NameBinding < ' ra > , bool ) > ,
6064 glob_res_outputs : Vec < ( NodeId , PartialRes ) > ,
6165 import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
6266}
@@ -66,20 +70,24 @@ impl<'r, 'ra, 'tcx> ImportResolver<'r, 'ra, 'tcx> {
6670 ImportResolver {
6771 r : cmr,
6872 batch,
69- determined_imports : Vec :: new ( ) ,
70- import_bindings : PerNS :: default ( ) ,
71- glob_import_outputs : Vec :: new ( ) ,
72- glob_res_outputs : Vec :: new ( ) ,
73+ prelude : None ,
74+ determined_imports : Default :: default ( ) ,
75+ module_glob_importers : Default :: default ( ) ,
76+ glob_import_bindings : Default :: default ( ) ,
77+ glob_res_outputs : Default :: default ( ) ,
78+ import_bindings : Default :: default ( ) ,
7379 }
7480 }
7581
7682 fn into_outputs ( self ) -> ImportResolutionOutputs < ' ra > {
7783 ImportResolutionOutputs {
84+ prelude : self . prelude ,
7885 indeterminate_imports : self . batch ,
7986 determined_imports : self . determined_imports ,
80- import_bindings : self . import_bindings ,
81- glob_import_outputs : self . glob_import_outputs ,
87+ module_glob_importers : self . module_glob_importers ,
88+ glob_import_bindings : self . glob_import_bindings ,
8289 glob_res_outputs : self . glob_res_outputs ,
90+ import_bindings : self . import_bindings ,
8391 }
8492 }
8593}
@@ -89,7 +97,17 @@ impl<'ra> ImportResolutionOutputs<'ra> {
8997 r. indeterminate_imports = self . indeterminate_imports ;
9098 r. determined_imports . extend ( self . determined_imports ) ;
9199
92- for ( module, key, binding, warn_ambiguity) in self . glob_import_outputs {
100+ // It's possible this particular round didn't set the prelude, so we should not
101+ // unset it in the main resolver.
102+ if self . prelude . is_some ( ) {
103+ r. prelude = self . prelude ;
104+ }
105+
106+ for ( module, glob_importers) in self . module_glob_importers {
107+ module. glob_importers . borrow_mut ( ) . extend ( glob_importers) ;
108+ }
109+
110+ for ( module, key, binding, warn_ambiguity) in self . glob_import_bindings {
93111 let _ = r. try_define_local ( module, key. ident . 0 , key. ns , binding, warn_ambiguity) ;
94112 }
95113
@@ -648,12 +666,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
648666 let mut prev_indeterminate_count = usize:: MAX ;
649667 let mut indeterminate_count = self . indeterminate_imports . len ( ) * 3 ;
650668 while indeterminate_count < prev_indeterminate_count {
651- self . assert_speculative = true ;
652669 prev_indeterminate_count = indeterminate_count;
653670 let batch = mem:: take ( & mut self . indeterminate_imports ) ;
671+ self . assert_speculative = true ;
654672 let ( outputs, count) = ImportResolver :: new ( self . cm ( ) , batch) . resolve_batch ( ) ;
655- indeterminate_count = count;
656673 self . assert_speculative = false ;
674+ indeterminate_count = count;
657675 outputs. commit ( self ) ;
658676 }
659677 }
@@ -1589,12 +1607,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15891607 if module == import. parent_scope . module {
15901608 return ;
15911609 } else if is_prelude {
1592- self . r . prelude . set ( Some ( module) ) ;
1610+ self . prelude = Some ( module) ;
15931611 return ;
15941612 }
15951613
15961614 // Add to module's glob_importers
1597- module . glob_importers . borrow_mut ( ) . push ( import) ;
1615+ self . module_glob_importers . entry ( module ) . or_default ( ) . push ( import) ;
15981616
15991617 // Ensure that `resolutions` isn't borrowed during `try_define`,
16001618 // since it might get updated via a glob cycle.
@@ -1618,7 +1636,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16181636 . resolution ( import. parent_scope . module , key)
16191637 . and_then ( |r| r. binding ( ) )
16201638 . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
1621- self . glob_import_outputs . push ( (
1639+ self . glob_import_bindings . push ( (
16221640 import. parent_scope . module ,
16231641 key,
16241642 imported_binding,
0 commit comments