@@ -32,10 +32,9 @@ use crate::errors::{
3232} ;
3333use crate :: ref_mut:: CmCell ;
3434use crate :: {
35- AmbiguityError , AmbiguityKind , BindingKey , CmResolver , Determinacy , Finalize , ImportSuggestion ,
36- Module , ModuleOrUniformRoot , NameBinding , NameBindingData , NameBindingKind , ParentScope ,
37- PathResult , PerNS , ResolutionError , Resolver , ScopeSet , Segment , Used , module_to_string,
38- names_to_string,
35+ AmbiguityKind , BindingKey , CmResolver , Determinacy , Finalize , ImportSuggestion , Module ,
36+ ModuleOrUniformRoot , NameBinding , NameBindingData , NameBindingKind , ParentScope , PathResult ,
37+ PerNS , ResolutionError , Resolver , ScopeSet , Segment , Used , module_to_string, names_to_string,
3938} ;
4039
4140type Res = def:: Res < NodeId > ;
@@ -325,7 +324,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
325324 self . arenas . alloc_name_binding ( NameBindingData {
326325 kind : NameBindingKind :: Import { binding, import } ,
327326 ambiguity : None ,
328- warn_ambiguity : false ,
329327 span : import. span ,
330328 vis,
331329 expansion : import. parent_scope . expansion ,
@@ -339,7 +337,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
339337 ident : Ident ,
340338 ns : Namespace ,
341339 binding : NameBinding < ' ra > ,
342- warn_ambiguity : bool ,
343340 ) -> Result < ( ) , NameBinding < ' ra > > {
344341 let res = binding. res ( ) ;
345342 self . check_reserved_macro_name ( ident, res) ;
@@ -351,7 +348,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
351348 module. underscore_disambiguator . update_unchecked ( |d| d + 1 ) ;
352349 module. underscore_disambiguator . get ( )
353350 } ) ;
354- self . update_local_resolution ( module, key, warn_ambiguity , |this, resolution| {
351+ self . update_local_resolution ( module, key, |this, resolution| {
355352 if let Some ( old_binding) = resolution. best_binding ( ) {
356353 if res == Res :: Err && old_binding. res ( ) != Res :: Err {
357354 // Do not override real bindings with `Res::Err`s from error recovery.
@@ -360,30 +357,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
360357 match ( old_binding. is_glob_import ( ) , binding. is_glob_import ( ) ) {
361358 ( true , true ) => {
362359 let ( glob_binding, old_glob_binding) = ( binding, old_binding) ;
363- // FIXME: remove `!binding.is_ambiguity_recursive()` after delete the warning ambiguity.
364- if !binding. is_ambiguity_recursive ( )
365- && let NameBindingKind :: Import { import : old_import, .. } =
366- old_glob_binding. kind
367- && let NameBindingKind :: Import { import, .. } = glob_binding. kind
368- && old_import == import
369- {
370- // When imported from the same glob-import statement, we should replace
371- // `old_glob_binding` with `glob_binding`, regardless of whether
372- // they have the same resolution or not.
373- resolution. glob_binding = Some ( glob_binding) ;
374- } else if res != old_glob_binding. res ( ) {
360+ if res != old_glob_binding. res ( ) {
375361 resolution. glob_binding = Some ( this. new_ambiguity_binding (
376362 AmbiguityKind :: GlobVsGlob ,
377363 old_glob_binding,
378364 glob_binding,
379- warn_ambiguity,
380365 ) ) ;
381- } else if !old_binding. vis . is_at_least ( binding. vis , this. tcx ) {
366+ } else if !old_glob_binding. vis . is_at_least ( glob_binding. vis , this. tcx )
367+ || glob_binding. is_ambiguity_recursive ( )
368+ {
382369 // We are glob-importing the same item but with greater visibility.
383370 resolution. glob_binding = Some ( glob_binding) ;
384- } else if binding. is_ambiguity_recursive ( ) {
385- resolution. glob_binding =
386- Some ( this. new_warn_ambiguity_binding ( glob_binding) ) ;
387371 }
388372 }
389373 ( old_glob @ true , false ) | ( old_glob @ false , true ) => {
@@ -397,7 +381,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
397381 AmbiguityKind :: GlobVsExpanded ,
398382 non_glob_binding,
399383 glob_binding,
400- false ,
401384 ) ) ;
402385 } else {
403386 resolution. non_glob_binding = Some ( non_glob_binding) ;
@@ -410,9 +393,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
410393 AmbiguityKind :: GlobVsGlob ,
411394 old_glob_binding,
412395 glob_binding,
413- false ,
414396 ) ) ;
415- } else if !old_glob_binding. vis . is_at_least ( binding. vis , this. tcx ) {
397+ } else if !old_glob_binding. vis . is_at_least ( glob_binding. vis , this. tcx )
398+ || glob_binding. is_ambiguity_recursive ( )
399+ {
400+ // We are glob-importing the same item but with greater visibility.
416401 resolution. glob_binding = Some ( glob_binding) ;
417402 }
418403 } else {
@@ -440,33 +425,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
440425 ambiguity_kind : AmbiguityKind ,
441426 primary_binding : NameBinding < ' ra > ,
442427 secondary_binding : NameBinding < ' ra > ,
443- warn_ambiguity : bool ,
444428 ) -> NameBinding < ' ra > {
445- let ambiguity = Some ( ( secondary_binding, ambiguity_kind) ) ;
446- let data = NameBindingData { ambiguity, warn_ambiguity , ..* primary_binding } ;
429+ let ambiguity = Some ( ( secondary_binding, ambiguity_kind, false ) ) ;
430+ let data = NameBindingData { ambiguity, ..* primary_binding } ;
447431 self . arenas . alloc_name_binding ( data)
448432 }
449433
450- fn new_warn_ambiguity_binding ( & self , binding : NameBinding < ' ra > ) -> NameBinding < ' ra > {
451- assert ! ( binding. is_ambiguity_recursive( ) ) ;
452- self . arenas . alloc_name_binding ( NameBindingData { warn_ambiguity : true , ..* binding } )
453- }
454-
455434 // Use `f` to mutate the resolution of the name in the module.
456435 // If the resolution becomes a success, define it in the module's glob importers.
457- fn update_local_resolution < T , F > (
458- & mut self ,
459- module : Module < ' ra > ,
460- key : BindingKey ,
461- warn_ambiguity : bool ,
462- f : F ,
463- ) -> T
436+ fn update_local_resolution < T , F > ( & mut self , module : Module < ' ra > , key : BindingKey , f : F ) -> T
464437 where
465438 F : FnOnce ( & Resolver < ' ra , ' tcx > , & mut NameResolution < ' ra > ) -> T ,
466439 {
467440 // Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
468441 // during which the resolution might end up getting re-defined via a glob cycle.
469- let ( binding, t, warn_ambiguity ) = {
442+ let ( binding, t) = {
470443 let resolution = & mut * self . resolution_or_default ( module, key) . borrow_mut_unchecked ( ) ;
471444 let old_binding = resolution. binding ( ) ;
472445
@@ -475,7 +448,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
475448 if let Some ( binding) = resolution. binding ( )
476449 && old_binding != Some ( binding)
477450 {
478- ( binding, t, warn_ambiguity || old_binding . is_some ( ) )
451+ ( binding, t)
479452 } else {
480453 return t;
481454 }
@@ -500,7 +473,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
500473 ident. 0 ,
501474 key. ns ,
502475 imported_binding,
503- warn_ambiguity,
504476 ) ;
505477 }
506478 }
@@ -521,11 +493,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
521493 let dummy_binding = self . import ( dummy_binding, import) ;
522494 self . per_ns ( |this, ns| {
523495 let module = import. parent_scope . module ;
524- let _ = this. try_define_local ( module, target, ns, dummy_binding, false ) ;
496+ let _ = this. try_define_local ( module, target, ns, dummy_binding) ;
525497 // Don't remove underscores from `single_imports`, they were never added.
526498 if target. name != kw:: Underscore {
527499 let key = BindingKey :: new ( target, ns) ;
528- this. update_local_resolution ( module, key, false , |_, resolution| {
500+ this. update_local_resolution ( module, key, |_, resolution| {
529501 resolution. single_imports . swap_remove ( & import) ;
530502 } )
531503 }
@@ -658,7 +630,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
658630 let Some ( binding) = resolution. best_binding ( ) else { continue } ;
659631
660632 if let NameBindingKind :: Import { import, .. } = binding. kind
661- && let Some ( ( amb_binding, _ ) ) = binding. ambiguity
633+ && let Some ( ( amb_binding, .. ) ) = binding. ambiguity
662634 && binding. res ( ) != Res :: Err
663635 && exported_ambiguities. contains ( & binding)
664636 {
@@ -917,7 +889,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
917889 this. get_mut_unchecked ( ) . update_local_resolution (
918890 parent,
919891 key,
920- false ,
921892 |_, resolution| {
922893 resolution. single_imports . swap_remove ( & import) ;
923894 } ,
@@ -946,9 +917,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
946917 ImportKind :: Single { bindings, .. } => bindings[ TypeNS ] . get ( ) . binding ( ) ,
947918 _ => None ,
948919 } ;
949- let ambiguity_errors_len =
950- |errors : & Vec < AmbiguityError < ' _ > > | errors. iter ( ) . filter ( |error| !error. warning ) . count ( ) ;
951- let prev_ambiguity_errors_len = ambiguity_errors_len ( & self . ambiguity_errors ) ;
920+ let prev_ambiguity_errors_len = self . ambiguity_errors . len ( ) ;
952921 let finalize = Finalize :: with_root_span ( import. root_id , import. span , import. root_span ) ;
953922
954923 // We'll provide more context to the privacy errors later, up to `len`.
@@ -963,8 +932,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
963932 Some ( import) ,
964933 ) ;
965934
966- let no_ambiguity =
967- ambiguity_errors_len ( & self . ambiguity_errors ) == prev_ambiguity_errors_len;
935+ let no_ambiguity = self . ambiguity_errors . len ( ) == prev_ambiguity_errors_len;
968936
969937 let module = match path_res {
970938 PathResult :: Module ( module) => {
@@ -1162,9 +1130,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11621130 initial_binding. res ( )
11631131 } ) ;
11641132 let res = binding. res ( ) ;
1165- let has_ambiguity_error =
1166- this. ambiguity_errors . iter ( ) . any ( |error| !error. warning ) ;
1167- if res == Res :: Err || has_ambiguity_error {
1133+ if res == Res :: Err || !this. ambiguity_errors . is_empty ( ) {
11681134 this. dcx ( )
11691135 . span_delayed_bug ( import. span , "some error happened for an import" ) ;
11701136 return ;
@@ -1523,16 +1489,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15231489 } ;
15241490 if self . is_accessible_from ( binding. vis , scope) {
15251491 let imported_binding = self . import ( binding, import) ;
1526- let warn_ambiguity = self
1527- . resolution ( import. parent_scope . module , key)
1528- . and_then ( |r| r. binding ( ) )
1529- . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
15301492 let _ = self . try_define_local (
15311493 import. parent_scope . module ,
15321494 key. ident . 0 ,
15331495 key. ns ,
15341496 imported_binding,
1535- warn_ambiguity,
15361497 ) ;
15371498 }
15381499 }
0 commit comments