@@ -49,24 +49,33 @@ pub(crate) struct ImportResolver<'r, 'ra, 'tcx> {
4949 // outputs
5050 determined_imports : Vec < Import < ' ra > > ,
5151 glob_imports : Vec < Import < ' ra > > ,
52+ import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
5253}
5354
5455struct ImportResolutionOutputs < ' ra > {
5556 indeterminate_imports : Vec < Import < ' ra > > ,
5657 determined_imports : Vec < Import < ' ra > > ,
5758 glob_imports : Vec < Import < ' ra > > ,
59+ import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
5860}
5961
6062impl < ' r , ' ra , ' tcx > ImportResolver < ' r , ' ra , ' tcx > {
6163 pub ( crate ) fn new ( cmr : CmResolver < ' r , ' ra , ' tcx > , batch : Vec < Import < ' ra > > ) -> Self {
62- ImportResolver { r : cmr, batch, determined_imports : Vec :: new ( ) , glob_imports : Vec :: new ( ) }
64+ ImportResolver {
65+ r : cmr,
66+ batch,
67+ determined_imports : Vec :: new ( ) ,
68+ glob_imports : Vec :: new ( ) ,
69+ import_bindings : PerNS :: default ( ) ,
70+ }
6371 }
6472
6573 fn into_outputs ( self ) -> ImportResolutionOutputs < ' ra > {
6674 ImportResolutionOutputs {
6775 indeterminate_imports : self . batch ,
6876 determined_imports : self . determined_imports ,
6977 glob_imports : self . glob_imports ,
78+ import_bindings : self . import_bindings ,
7079 }
7180 }
7281}
@@ -78,6 +87,27 @@ impl<'ra> ImportResolutionOutputs<'ra> {
7887 for glob in self . glob_imports {
7988 r. resolve_glob_import ( glob) ;
8089 }
90+
91+ for ( ns, import_bindings) in self . import_bindings . into_iter_with ( ) {
92+ for ( parent, import, pending_binding) in import_bindings {
93+ let ImportKind :: Single { target, ref bindings, .. } = import. kind else {
94+ unreachable ! ( ) ;
95+ } ;
96+ match pending_binding {
97+ PendingBinding :: Ready ( Some ( binding) ) => {
98+ r. define_binding_local ( parent, target, ns, binding) ;
99+ }
100+ PendingBinding :: Ready ( None ) => {
101+ let key = BindingKey :: new ( target, ns) ;
102+ r. update_local_resolution ( parent, key, false , |_, resolution| {
103+ resolution. single_imports . swap_remove ( & import) ;
104+ } ) ;
105+ }
106+ _ => { }
107+ }
108+ bindings[ ns] . set ( pending_binding) ;
109+ }
110+ }
81111 }
82112}
83113
@@ -927,6 +957,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
927957 }
928958 } ;
929959
960+ // FIXME: isolate if not a cache.
930961 import. imported_module . set ( Some ( module) ) ;
931962 let ( source, target, bindings, type_ns_only) = match import. kind {
932963 ImportKind :: Single { source, target, ref bindings, type_ns_only, .. } => {
@@ -953,7 +984,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
953984 Some ( import) ,
954985 ) ;
955986 let parent = import. parent_scope . module ;
956- let binding = match binding_result {
987+ let pending_binding = match binding_result {
957988 Ok ( binding) => {
958989 if binding. is_assoc_item ( )
959990 && !this. tcx . features ( ) . import_trait_associated_functions ( )
@@ -968,39 +999,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
968999 }
9691000 // We need the `target`, `source` can be extracted.
9701001 let imported_binding = this. import ( binding, import) ;
971- // FIXME: Use mutable resolver directly as a hack, this should be an output of
972- // specualtive resolution.
973- this. get_mut_unchecked ( ) . define_binding_local (
974- parent,
975- target,
976- ns,
977- imported_binding,
978- ) ;
9791002 PendingBinding :: Ready ( Some ( imported_binding) )
9801003 }
9811004 Err ( Determinacy :: Determined ) => {
9821005 // Don't remove underscores from `single_imports`, they were never added.
983- if target. name != kw:: Underscore {
984- let key = BindingKey :: new ( target, ns) ;
985- // FIXME: Use mutable resolver directly as a hack, this should be an output of
986- // specualtive resolution.
987- this. get_mut_unchecked ( ) . update_local_resolution (
988- parent,
989- key,
990- false ,
991- |_, resolution| {
992- resolution. single_imports . swap_remove ( & import) ;
993- } ,
994- ) ;
1006+ if target. name == kw:: Underscore {
1007+ return ;
9951008 }
9961009 PendingBinding :: Ready ( None )
9971010 }
9981011 Err ( Determinacy :: Undetermined ) => {
9991012 indeterminate_count += 1 ;
1000- PendingBinding :: Pending
1013+ return ;
10011014 }
10021015 } ;
1003- bindings [ ns] . set ( binding ) ;
1016+ self . import_bindings [ ns] . push ( ( parent , import , pending_binding ) ) ;
10041017 }
10051018 } ) ;
10061019
0 commit comments