@@ -305,10 +305,10 @@ fn remove_same_import<'ra>(
305305 if let NameBindingKind :: Import { import : import1, binding : b1_next } = b1. kind
306306 && let NameBindingKind :: Import { import : import2, binding : b2_next } = b2. kind
307307 && import1 == import2
308- && b1. ambiguity == b2. ambiguity
308+ && b1. warn_ambiguity . get ( ) == b2. warn_ambiguity . get ( )
309309 {
310- assert ! ( b1. ambiguity. is_none ( ) ) ;
311- assert_eq ! ( b1 . warn_ambiguity . get ( ) , b2 . warn_ambiguity. get( ) ) ;
310+ assert_eq ! ( b1. ambiguity. get ( ) , b2 . ambiguity . get ( ) ) ;
311+ assert ! ( !b1 . warn_ambiguity. get( ) ) ;
312312 assert_eq ! ( b1. expansion, b2. expansion) ;
313313 assert_eq ! ( b1. span, b2. span) ;
314314 assert_eq ! ( b1. vis( ) , b2. vis( ) ) ;
@@ -344,7 +344,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
344344
345345 self . arenas . alloc_name_binding ( NameBindingData {
346346 kind : NameBindingKind :: Import { binding, import } ,
347- ambiguity : None ,
347+ ambiguity : CmCell :: new ( None ) ,
348348 warn_ambiguity : CmCell :: new ( false ) ,
349349 span : import. span ,
350350 vis : CmCell :: new ( vis) ,
@@ -368,9 +368,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
368368 // all these overwrites will be re-fetched by glob imports importing
369369 // from that module without generating new ambiguities.
370370 // - A glob binding is overwritten by a non-glob binding arriving later.
371- // - A glob binding is overwritten by an ambiguous glob binding .
372- // FIXME: avoid this by putting `NameBindingData::ambiguity` under a
373- // cell and updating it in place .
371+ // - A glob binding is overwritten by its clone after setting ambiguity in it .
372+ // FIXME: avoid this by removing `warn_ambiguity`, or by triggering glob re-fetch
373+ // with the same binding in some way .
374374 // - A glob binding is overwritten by a glob binding re-fetching an
375375 // overwritten binding from other module (the recursive case).
376376 // Here we are detecting all such re-fetches and overwrite old bindings
@@ -381,14 +381,25 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
381381 if deep_binding != glob_binding {
382382 // Some import layers have been removed, need to overwrite.
383383 assert_ne ! ( old_deep_binding, old_glob_binding) ;
384- assert_ne ! ( old_deep_binding, deep_binding) ;
385- assert ! ( old_deep_binding. is_glob_import( ) ) ;
384+ // FIXME: reenable the asserts when `warn_ambiguity` is removed (#149195).
385+ // assert_ne!(old_deep_binding, deep_binding);
386+ // assert!(old_deep_binding.is_glob_import());
387+ assert ! ( !deep_binding. is_glob_import( ) ) ;
386388 if glob_binding. is_ambiguity_recursive ( ) {
387389 glob_binding. warn_ambiguity . set_unchecked ( true ) ;
388390 }
389391 glob_binding
390392 } else if glob_binding. res ( ) != old_glob_binding. res ( ) {
391- self . new_ambiguity_binding ( old_glob_binding, glob_binding, warn_ambiguity)
393+ old_glob_binding. ambiguity . set_unchecked ( Some ( glob_binding) ) ;
394+ old_glob_binding. warn_ambiguity . set_unchecked ( warn_ambiguity) ;
395+ if warn_ambiguity {
396+ old_glob_binding
397+ } else {
398+ // Need a fresh binding so other glob imports importing it could re-fetch it
399+ // and set their own `warn_ambiguity` to true.
400+ // FIXME: remove this when `warn_ambiguity` is removed (#149195).
401+ self . arenas . alloc_name_binding ( ( * old_glob_binding) . clone ( ) )
402+ }
392403 } else if !old_glob_binding. vis ( ) . is_at_least ( glob_binding. vis ( ) , self . tcx ) {
393404 // We are glob-importing the same item but with greater visibility.
394405 old_glob_binding. vis . set_unchecked ( glob_binding. vis ( ) ) ;
@@ -397,12 +408,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
397408 && !old_glob_binding. is_ambiguity_recursive ( )
398409 {
399410 // Overwriting a non-ambiguous glob import with an ambiguous glob import.
400- self . new_ambiguity_binding (
401- AmbiguityKind :: GlobVsGlob ,
402- old_glob_binding,
403- glob_binding,
404- true ,
405- )
411+ old_glob_binding. ambiguity . set_unchecked ( Some ( glob_binding) ) ;
412+ old_glob_binding. warn_ambiguity . set_unchecked ( true ) ;
413+ old_glob_binding
406414 } else {
407415 old_glob_binding
408416 }
@@ -430,6 +438,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
430438 self . update_local_resolution ( module, key, warn_ambiguity, |this, resolution| {
431439 if let Some ( old_binding) = resolution. best_binding ( ) {
432440 assert_ne ! ( binding, old_binding) ;
441+ assert ! ( !binding. warn_ambiguity. get( ) ) ;
433442 if res == Res :: Err && old_binding. res ( ) != Res :: Err {
434443 // Do not override real bindings with `Res::Err`s from error recovery.
435444 return Ok ( ( ) ) ;
@@ -471,19 +480,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
471480 } )
472481 }
473482
474- fn new_ambiguity_binding (
475- & self ,
476- primary_binding : NameBinding < ' ra > ,
477- secondary_binding : NameBinding < ' ra > ,
478- warn_ambiguity : bool ,
479- ) -> NameBinding < ' ra > {
480- let ambiguity = Some ( secondary_binding) ;
481- let warn_ambiguity = CmCell :: new ( warn_ambiguity) ;
482- let vis = primary_binding. vis . clone ( ) ;
483- let data = NameBindingData { ambiguity, warn_ambiguity, vis, ..* primary_binding } ;
484- self . arenas . alloc_name_binding ( data)
485- }
486-
487483 // Use `f` to mutate the resolution of the name in the module.
488484 // If the resolution becomes a success, define it in the module's glob importers.
489485 fn update_local_resolution < T , F > (
@@ -690,7 +686,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
690686 let Some ( binding) = resolution. best_binding ( ) else { continue } ;
691687
692688 if let NameBindingKind :: Import { import, .. } = binding. kind
693- && let Some ( amb_binding) = binding. ambiguity
689+ && let Some ( amb_binding) = binding. ambiguity . get ( )
694690 && binding. res ( ) != Res :: Err
695691 && exported_ambiguities. contains ( & binding)
696692 {
0 commit comments