@@ -469,7 +469,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
469
469
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
470
470
// during which the resolution might end up getting re-defined via a glob cycle.
471
471
let ( binding, t, warn_ambiguity) = {
472
- let resolution = & mut * self . resolution ( module, key) . borrow_mut ( ) ;
472
+ let resolution = & mut * self . resolution_or_default ( module, key) . borrow_mut ( ) ;
473
473
let old_binding = resolution. binding ( ) ;
474
474
475
475
let t = f ( self , resolution) ;
@@ -651,7 +651,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
651
651
for module in self . arenas . local_modules ( ) . iter ( ) {
652
652
for ( key, resolution) in self . resolutions ( * module) . borrow ( ) . iter ( ) {
653
653
let resolution = resolution. borrow ( ) ;
654
-
655
654
let Some ( binding) = resolution. best_binding ( ) else { continue } ;
656
655
657
656
if let NameBindingKind :: Import { import, .. } = binding. kind
@@ -1202,41 +1201,39 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1202
1201
} ) ;
1203
1202
1204
1203
return if all_ns_failed {
1205
- let resolutions = match module {
1206
- ModuleOrUniformRoot :: Module ( module) => Some ( self . resolutions ( module) . borrow ( ) ) ,
1207
- _ => None ,
1208
- } ;
1209
- let resolutions = resolutions. as_ref ( ) . into_iter ( ) . flat_map ( |r| r. iter ( ) ) ;
1210
- let names = resolutions
1211
- . filter_map ( |( BindingKey { ident : i, .. } , resolution) | {
1212
- if i. name == ident. name {
1213
- return None ;
1214
- } // Never suggest the same name
1215
- match * resolution. borrow ( ) {
1216
- ref resolution
1217
- if let Some ( name_binding) = resolution. best_binding ( ) =>
1218
- {
1219
- match name_binding. kind {
1220
- NameBindingKind :: Import { binding, .. } => {
1221
- match binding. kind {
1222
- // Never suggest the name that has binding error
1223
- // i.e., the name that cannot be previously resolved
1224
- NameBindingKind :: Res ( Res :: Err ) => None ,
1225
- _ => Some ( i. name ) ,
1204
+ let names = match module {
1205
+ ModuleOrUniformRoot :: Module ( module) => {
1206
+ self . resolutions ( module)
1207
+ . borrow ( )
1208
+ . iter ( )
1209
+ . filter_map ( |( BindingKey { ident : i, .. } , resolution) | {
1210
+ if i. name == ident. name {
1211
+ return None ;
1212
+ } // Never suggest the same name
1213
+
1214
+ let resolution = resolution. borrow ( ) ;
1215
+ if let Some ( name_binding) = resolution. best_binding ( ) {
1216
+ match name_binding. kind {
1217
+ NameBindingKind :: Import { binding, .. } => {
1218
+ match binding. kind {
1219
+ // Never suggest the name that has binding error
1220
+ // i.e., the name that cannot be previously resolved
1221
+ NameBindingKind :: Res ( Res :: Err ) => None ,
1222
+ _ => Some ( i. name ) ,
1223
+ }
1226
1224
}
1225
+ _ => Some ( i. name ) ,
1227
1226
}
1228
- _ => Some ( i. name ) ,
1227
+ } else if resolution. single_imports . is_empty ( ) {
1228
+ None
1229
+ } else {
1230
+ Some ( i. name )
1229
1231
}
1230
- }
1231
- NameResolution { ref single_imports, .. }
1232
- if single_imports. is_empty ( ) =>
1233
- {
1234
- None
1235
- }
1236
- _ => Some ( i. name ) ,
1237
- }
1238
- } )
1239
- . collect :: < Vec < Symbol > > ( ) ;
1232
+ } )
1233
+ . collect ( )
1234
+ }
1235
+ _ => Vec :: new ( ) ,
1236
+ } ;
1240
1237
1241
1238
let lev_suggestion =
1242
1239
find_best_match_for_name ( & names, ident. name , None ) . map ( |suggestion| {
@@ -1517,8 +1514,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1517
1514
let imported_binding = self . import ( binding, import) ;
1518
1515
let warn_ambiguity = self
1519
1516
. resolution ( import. parent_scope . module , key)
1520
- . borrow ( )
1521
- . binding ( )
1517
+ . and_then ( |r| r. binding ( ) )
1522
1518
. is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
1523
1519
let _ = self . try_define (
1524
1520
import. parent_scope . module ,
0 commit comments