@@ -300,13 +300,16 @@ fn remove_same_import<'ra>(d1: Decl<'ra>, d2: Decl<'ra>) -> (Decl<'ra>, Decl<'ra
300300 if let DeclKind :: Import { import : import1, source_decl : d1_next } = d1. kind
301301 && let DeclKind :: Import { import : import2, source_decl : d2_next } = d2. kind
302302 && import1 == import2
303- && d1. warn_ambiguity . get ( ) == d2. warn_ambiguity . get ( )
304303 {
305- assert_eq ! ( d1. ambiguity. get( ) , d2. ambiguity. get( ) ) ;
306- assert ! ( !d1. warn_ambiguity. get( ) ) ;
307304 assert_eq ! ( d1. expansion, d2. expansion) ;
308305 assert_eq ! ( d1. span, d2. span) ;
309- assert_eq ! ( d1. vis( ) , d2. vis( ) ) ;
306+ if d1. ambiguity . get ( ) != d2. ambiguity . get ( ) {
307+ assert ! ( d1. ambiguity. get( ) . is_some( ) ) ;
308+ assert ! ( d2. ambiguity. get( ) . is_none( ) ) ;
309+ }
310+ // Visibility of the new import declaration may be different,
311+ // because it already incorporates the visibility of the source binding.
312+ // `warn_ambiguity` of a re-fetched glob can also change in both directions.
310313 remove_same_import ( d1_next, d2_next)
311314 } else {
312315 ( d1, d2)
@@ -348,8 +351,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
348351 /// decide which one to keep.
349352 fn select_glob_decl (
350353 & self ,
351- glob_decl : Decl < ' ra > ,
352354 old_glob_decl : Decl < ' ra > ,
355+ glob_decl : Decl < ' ra > ,
353356 warn_ambiguity : bool ,
354357 ) -> Decl < ' ra > {
355358 assert ! ( glob_decl. is_glob_import( ) ) ;
@@ -369,14 +372,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
369372 // with the re-fetched decls.
370373 // This is probably incorrect in corner cases, and the outdated decls still get
371374 // propagated to other places and get stuck there, but that's what we have at the moment.
372- let ( deep_decl , old_deep_decl ) = remove_same_import ( glob_decl , old_glob_decl ) ;
375+ let ( old_deep_decl , deep_decl ) = remove_same_import ( old_glob_decl , glob_decl ) ;
373376 if deep_decl != glob_decl {
374377 // Some import layers have been removed, need to overwrite.
375378 assert_ne ! ( old_deep_decl, old_glob_decl) ;
376379 // FIXME: reenable the asserts when `warn_ambiguity` is removed (#149195).
377380 // assert_ne!(old_deep_decl, deep_decl);
378381 // assert!(old_deep_decl.is_glob_import());
379382 assert ! ( !deep_decl. is_glob_import( ) ) ;
383+ if old_glob_decl. ambiguity . get ( ) . is_some ( ) && glob_decl. ambiguity . get ( ) . is_none ( ) {
384+ // Do not lose glob ambiguities when re-fetching the glob.
385+ glob_decl. ambiguity . set_unchecked ( old_glob_decl. ambiguity . get ( ) ) ;
386+ }
380387 if glob_decl. is_ambiguity_recursive ( ) {
381388 glob_decl. warn_ambiguity . set_unchecked ( true ) ;
382389 }
@@ -436,7 +443,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
436443 match ( old_decl. is_glob_import ( ) , decl. is_glob_import ( ) ) {
437444 ( true , true ) => {
438445 resolution. glob_decl =
439- Some ( this. select_glob_decl ( decl , old_decl , warn_ambiguity) ) ;
446+ Some ( this. select_glob_decl ( old_decl , decl , warn_ambiguity) ) ;
440447 }
441448 ( old_glob @ true , false ) | ( old_glob @ false , true ) => {
442449 let ( glob_decl, non_glob_decl) =
@@ -446,7 +453,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
446453 && old_glob_decl != glob_decl
447454 {
448455 resolution. glob_decl =
449- Some ( this. select_glob_decl ( glob_decl , old_glob_decl , false ) ) ;
456+ Some ( this. select_glob_decl ( old_glob_decl , glob_decl , false ) ) ;
450457 } else {
451458 resolution. glob_decl = Some ( glob_decl) ;
452459 }
0 commit comments