@@ -571,6 +571,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
571
571
if let ImportKind :: Single { source, ref bindings, .. } = import. kind
572
572
&& source. name == kw:: SelfLower
573
573
// Silence `unresolved import` error if E0429 is already emitted
574
+ // `indings` here is "target_bindings", if it is "Err(Determined)" then `source_bindings` as well.
574
575
&& let Progress :: Ready ( None ) = bindings. value_ns . get ( )
575
576
{
576
577
continue ;
@@ -835,15 +836,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
835
836
self . per_ns ( |this, ns| {
836
837
if !type_ns_only || ns == TypeNS {
837
838
if let Progress :: Pending = bindings[ ns] . get ( ) {
838
- let binding = this. maybe_resolve_ident_in_module (
839
+ let binding_result = this. maybe_resolve_ident_in_module (
839
840
module,
840
841
source,
841
842
ns,
842
843
& import. parent_scope ,
843
844
Some ( import) ,
844
845
) ;
845
- let binding = match binding {
846
- Ok ( binding) => Poll :: Ready ( Some ( binding) ) ,
846
+ let binding = match binding_result {
847
+ // We need the `target`, `source` can be extracted.
848
+ Ok ( binding) => Poll :: Ready ( Some ( this. import ( binding, import) ) ) ,
847
849
Err ( Determinacy :: Determined ) => Poll :: Ready ( None ) ,
848
850
Err ( Determinacy :: Undetermined ) => Poll :: Pending ,
849
851
} ;
@@ -866,10 +868,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
866
868
)
867
869
. emit ( ) ;
868
870
}
869
-
870
- let imported_binding = this. import ( binding, import) ;
871
- // target_bindings[ns].set(Some(imported_binding));
872
- this. define ( parent, target, ns, imported_binding) ;
871
+ this. define ( parent, target, ns, binding) ;
873
872
}
874
873
Progress :: Ready ( None ) => {
875
874
// Don't update the resolution for underscores, because it was never added.
@@ -1104,21 +1103,25 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1104
1103
match binding {
1105
1104
Ok ( binding) => {
1106
1105
// Consistency checks, analogous to `finalize_macro_resolutions`.
1107
- let initial_res = bindings[ ns] . get ( ) . map ( |initial_binding| {
1108
- all_ns_err = false ;
1109
- if let Some ( binding) = initial_binding
1110
- && target. name == kw:: Underscore
1111
- && binding. is_extern_crate ( )
1112
- && !binding. is_import ( )
1113
- {
1114
- let used = if import. module_path . is_empty ( ) {
1115
- Used :: Scope
1116
- } else {
1117
- Used :: Other
1118
- } ;
1119
- this. record_use ( ident, binding, used) ;
1120
- }
1121
- binding. res ( )
1106
+ let initial_res = bindings[ ns] . get ( ) . map ( |maybe_binding| {
1107
+ maybe_binding. and_then ( |binding| binding. maybe_source_binding ( ) ) . map (
1108
+ |initial_binding| {
1109
+ all_ns_err = false ;
1110
+ if let Progress :: Ready ( Some ( binding) ) = bindings[ ns] . get ( )
1111
+ && target. name == kw:: Underscore
1112
+ && initial_binding. is_extern_crate ( )
1113
+ && !initial_binding. is_import ( )
1114
+ {
1115
+ let used = if import. module_path . is_empty ( ) {
1116
+ Used :: Scope
1117
+ } else {
1118
+ Used :: Other
1119
+ } ;
1120
+ this. record_use ( ident, binding, used) ;
1121
+ }
1122
+ binding. res ( )
1123
+ } ,
1124
+ )
1122
1125
} ) ;
1123
1126
let res = binding. res ( ) ;
1124
1127
let has_ambiguity_error =
@@ -1128,7 +1131,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1128
1131
. span_delayed_bug ( import. span , "some error happened for an import" ) ;
1129
1132
return ;
1130
1133
}
1131
- if let Progress :: Ready ( initial_res) = initial_res {
1134
+ if let Progress :: Ready ( Some ( initial_res) ) = initial_res {
1132
1135
if res != initial_res {
1133
1136
span_bug ! ( import. span, "inconsistent resolution for an import" ) ;
1134
1137
}
@@ -1271,7 +1274,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1271
1274
let mut any_successful_reexport = false ;
1272
1275
let mut crate_private_reexport = false ;
1273
1276
self . per_ns ( |this, ns| {
1274
- let Progress :: Ready ( Some ( binding) ) = bindings[ ns] . get ( ) else {
1277
+ let binding = match bindings[ ns] . get ( ) {
1278
+ Poll :: Ready ( Some ( binding) ) => binding. maybe_source_binding ( ) ,
1279
+ _ => None ,
1280
+ } ;
1281
+ let Some ( binding) = binding else {
1275
1282
return ;
1276
1283
} ;
1277
1284
@@ -1352,7 +1359,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1352
1359
// this may resolve to either a value or a type, but for documentation
1353
1360
// purposes it's good enough to just favor one over the other.
1354
1361
self . per_ns ( |this, ns| {
1355
- if let Progress :: Ready ( Some ( binding) ) = bindings[ ns] . get ( ) {
1362
+ let binding = match bindings[ ns] . get ( ) {
1363
+ Poll :: Ready ( Some ( binding) ) => binding. maybe_source_binding ( ) ,
1364
+ _ => None ,
1365
+ } ;
1366
+ if let Some ( binding) = binding {
1356
1367
this. import_res_map . entry ( import_id) . or_default ( ) [ ns] = Some ( binding. res ( ) ) ;
1357
1368
}
1358
1369
} ) ;
@@ -1390,7 +1401,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1390
1401
let mut is_redundant = true ;
1391
1402
let mut redundant_span = PerNS { value_ns : None , type_ns : None , macro_ns : None } ;
1392
1403
self . per_ns ( |this, ns| {
1393
- if is_redundant && let Poll :: Ready ( Some ( binding) ) = bindings[ ns] . get ( ) {
1404
+ let binding = match bindings[ ns] . get ( ) {
1405
+ Poll :: Ready ( Some ( binding) ) => binding. maybe_source_binding ( ) ,
1406
+ _ => None ,
1407
+ } ;
1408
+ if is_redundant && let Some ( binding) = binding {
1394
1409
if binding. res ( ) == Res :: Err {
1395
1410
return ;
1396
1411
}
0 commit comments