@@ -375,6 +375,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
375375 module. underscore_disambiguator . update_unchecked ( |d| d + 1 ) ;
376376 module. underscore_disambiguator . get ( )
377377 } ) ;
378+ let tcx = self . tcx ( ) ;
379+ // "Same res different import" ambiguity hack for macros introduced in #145108.
380+ // See related discussion for more info:
381+ // https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/near/542057918.
382+ if ns == MacroNS && binding. is_glob_import ( ) {
383+ if let Some ( def_id) = res. opt_def_id ( ) {
384+ self . greatest_vis_map
385+ . entry ( def_id)
386+ . and_modify ( |vis| {
387+ if !vis. is_at_least ( binding. vis , tcx) {
388+ * vis = binding. vis
389+ }
390+ } )
391+ . or_insert ( binding. vis ) ;
392+ }
393+ }
378394 self . update_local_resolution ( module, key, warn_ambiguity, |this, resolution| {
379395 if let Some ( old_binding) = resolution. best_binding ( ) {
380396 if res == Res :: Err && old_binding. res ( ) != Res :: Err {
@@ -624,12 +640,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
624640 for ( import, side_effect) in import_resolutions {
625641 let SideEffect { imported_module, bindings : side_effect_bindings } = side_effect;
626642 let parent = import. parent_scope . module ;
627-
628643 match ( & import. kind , side_effect_bindings) {
629644 (
630645 ImportKind :: Single { target, bindings, .. } ,
631646 SideEffectBindings :: Single { import_bindings } ,
632647 ) => {
648+ debug ! ( "{import_bindings:#?}" ) ;
633649 self . per_ns ( |this, ns| {
634650 match import_bindings[ ns] {
635651 Some ( Some ( binding) ) => {
@@ -688,6 +704,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
688704 . resolution ( import. parent_scope . module , key)
689705 . and_then ( |r| r. binding ( ) )
690706 . is_some_and ( |binding| binding. warn_ambiguity_recursive ( ) ) ;
707+ debug ! ( "defining binding from glob: {imported_binding:#?}" ) ;
691708 let _ = self . try_define_local (
692709 parent,
693710 key. ident . 0 ,
@@ -1656,7 +1673,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16561673 next_binding = binding;
16571674 }
16581675
1659- children. push ( ModChild { ident : ident. 0 , res, vis : binding. vis , reexport_chain } ) ;
1676+ let vis = match res. opt_def_id ( ) {
1677+ Some ( def_id) => {
1678+ self . greatest_vis_map . get ( & def_id) . copied ( ) . unwrap_or ( binding. vis )
1679+ }
1680+ None => binding. vis ,
1681+ } ;
1682+ children. push ( ModChild { ident : ident. 0 , res, vis, reexport_chain } ) ;
16601683 }
16611684 } ) ;
16621685
0 commit comments