@@ -469,7 +469,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
469469 // Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
470470 // during which the resolution might end up getting re-defined via a glob cycle.
471471 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 ( ) ;
473473 let old_binding = resolution. binding ( ) ;
474474
475475 let t = f ( self , resolution) ;
@@ -651,7 +651,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
651651 for module in self . arenas . local_modules ( ) . iter ( ) {
652652 for ( key, resolution) in self . resolutions ( * module) . borrow ( ) . iter ( ) {
653653 let resolution = resolution. borrow ( ) ;
654-
655654 let Some ( binding) = resolution. best_binding ( ) else { continue } ;
656655
657656 if let NameBindingKind :: Import { import, .. } = binding. kind
@@ -1202,41 +1201,39 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12021201 } ) ;
12031202
12041203 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+ }
12261224 }
1225+ _ => Some ( i. name ) ,
12271226 }
1228- _ => Some ( i. name ) ,
1227+ } else if resolution. single_imports . is_empty ( ) {
1228+ None
1229+ } else {
1230+ Some ( i. name )
12291231 }
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+ } ;
12401237
12411238 let lev_suggestion =
12421239 find_best_match_for_name ( & names, ident. name , None ) . map ( |suggestion| {
@@ -1517,8 +1514,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15171514 let imported_binding = self . import ( binding, import) ;
15181515 let warn_ambiguity = self
15191516 . resolution ( import. parent_scope . module , key)
1520- . borrow ( )
1521- . binding ( )
1517+ . and_then ( |r| r. binding ( ) )
15221518 . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
15231519 let _ = self . try_define (
15241520 import. parent_scope . module ,
0 commit comments