@@ -640,6 +640,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
640640
641641 match result {
642642 Ok ( ( binding, flags) ) => {
643+ if !matches ! ( scope, Scope :: MacroUsePrelude ) {
644+ let adjusted_module = if let Scope :: Module ( module, _) = scope
645+ && !matches ! ( scope_set, ScopeSet :: ModuleAndExternPrelude ( ..) )
646+ {
647+ module
648+ } else {
649+ parent_scope. module
650+ } ;
651+ if !this. is_accessible_from ( binding. vis , adjusted_module) {
652+ this. dcx ( )
653+ . struct_span_err ( binding. span , "binding" )
654+ . with_span_label ( adjusted_module. span , "module" )
655+ . emit ( ) ;
656+ }
657+ }
658+
643659 if !sub_namespace_match ( binding. macro_kinds ( ) , macro_kind) {
644660 return None ;
645661 }
@@ -648,14 +664,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
648664 // We do not need to report them if we are either in speculative resolution,
649665 // or in late resolution when everything is already imported and expanded
650666 // and no ambiguities exist.
651- if matches ! ( finalize, None | Some ( Finalize { stage: Stage :: Late , .. } ) ) {
652- return Some ( Ok ( binding) ) ;
653- }
667+ let significant_visibility = match finalize {
668+ None | Some ( Finalize { stage : Stage :: Late , .. } ) => {
669+ return Some ( Ok ( binding) ) ;
670+ }
671+ Some ( Finalize { significant_visibility, .. } ) => significant_visibility,
672+ } ;
654673
655674 if let Some ( ( innermost_binding, innermost_flags) ) = innermost_result {
656675 // Found another solution, if the first one was "weak", report an error.
657676 let ( res, innermost_res) = ( binding. res ( ) , innermost_binding. res ( ) ) ;
658- if res != innermost_res {
677+ if res != innermost_res || significant_visibility {
659678 let is_builtin = |res| {
660679 matches ! ( res, Res :: NonMacroAttr ( NonMacroAttrKind :: Builtin ( ..) ) )
661680 } ;
@@ -1065,7 +1084,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10651084 && shadowing == Shadowing :: Restricted
10661085 && finalize. stage == Stage :: Early
10671086 && binding. expansion != LocalExpnId :: ROOT
1068- && binding. res ( ) != shadowed_glob. res ( )
1087+ && ( binding. res ( ) != shadowed_glob. res ( ) || finalize . significant_visibility )
10691088 {
10701089 self . ambiguity_errors . push ( AmbiguityError {
10711090 kind : AmbiguityKind :: GlobVsExpanded ,
0 commit comments