@@ -49,24 +49,33 @@ pub(crate) struct ImportResolver<'r, 'ra, 'tcx> {
49
49
// outputs
50
50
determined_imports : Vec < Import < ' ra > > ,
51
51
glob_imports : Vec < Import < ' ra > > ,
52
+ import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
52
53
}
53
54
54
55
struct ImportResolutionOutputs < ' ra > {
55
56
indeterminate_imports : Vec < Import < ' ra > > ,
56
57
determined_imports : Vec < Import < ' ra > > ,
57
58
glob_imports : Vec < Import < ' ra > > ,
59
+ import_bindings : PerNS < Vec < ( Module < ' ra > , Import < ' ra > , PendingBinding < ' ra > ) > > ,
58
60
}
59
61
60
62
impl < ' r , ' ra , ' tcx > ImportResolver < ' r , ' ra , ' tcx > {
61
63
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
+ }
63
71
}
64
72
65
73
fn into_outputs ( self ) -> ImportResolutionOutputs < ' ra > {
66
74
ImportResolutionOutputs {
67
75
indeterminate_imports : self . batch ,
68
76
determined_imports : self . determined_imports ,
69
77
glob_imports : self . glob_imports ,
78
+ import_bindings : self . import_bindings ,
70
79
}
71
80
}
72
81
}
@@ -78,6 +87,27 @@ impl<'ra> ImportResolutionOutputs<'ra> {
78
87
for glob in self . glob_imports {
79
88
r. resolve_glob_import ( glob) ;
80
89
}
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
+ }
81
111
}
82
112
}
83
113
@@ -927,6 +957,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
927
957
}
928
958
} ;
929
959
960
+ // FIXME: isolate if not a cache.
930
961
import. imported_module . set ( Some ( module) ) ;
931
962
let ( source, target, bindings, type_ns_only) = match import. kind {
932
963
ImportKind :: Single { source, target, ref bindings, type_ns_only, .. } => {
@@ -953,7 +984,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
953
984
Some ( import) ,
954
985
) ;
955
986
let parent = import. parent_scope . module ;
956
- let binding = match binding_result {
987
+ let pending_binding = match binding_result {
957
988
Ok ( binding) => {
958
989
if binding. is_assoc_item ( )
959
990
&& !this. tcx . features ( ) . import_trait_associated_functions ( )
@@ -968,39 +999,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
968
999
}
969
1000
// We need the `target`, `source` can be extracted.
970
1001
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
- ) ;
979
1002
PendingBinding :: Ready ( Some ( imported_binding) )
980
1003
}
981
1004
Err ( Determinacy :: Determined ) => {
982
1005
// 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 ;
995
1008
}
996
1009
PendingBinding :: Ready ( None )
997
1010
}
998
1011
Err ( Determinacy :: Undetermined ) => {
999
1012
indeterminate_count += 1 ;
1000
- PendingBinding :: Pending
1013
+ return ;
1001
1014
}
1002
1015
} ;
1003
- bindings [ ns] . set ( binding ) ;
1016
+ self . import_bindings [ ns] . push ( ( parent , import , pending_binding ) ) ;
1004
1017
}
1005
1018
} ) ;
1006
1019
0 commit comments