@@ -1029,9 +1029,9 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10291029 }
10301030 }
10311031
1032- let macro_use_import = |this : & Self , span| {
1032+ let macro_use_import = |this : & Self , span, warn_private | {
10331033 this. r . arenas . alloc_import ( ImportData {
1034- kind : ImportKind :: MacroUse ,
1034+ kind : ImportKind :: MacroUse { warn_private } ,
10351035 root_id : item. id ,
10361036 parent_scope : this. parent_scope ,
10371037 imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
@@ -1048,11 +1048,25 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10481048
10491049 let allow_shadowing = self . parent_scope . expansion == LocalExpnId :: ROOT ;
10501050 if let Some ( span) = import_all {
1051- let import = macro_use_import ( self , span) ;
1051+ let import = macro_use_import ( self , span, false ) ;
10521052 self . r . potentially_unused_imports . push ( import) ;
10531053 module. for_each_child ( self , |this, ident, ns, binding| {
10541054 if ns == MacroNS {
1055- let imported_binding = this. r . import ( binding, import) ;
1055+ let imported_binding =
1056+ if this. r . is_accessible_from ( binding. vis , this. parent_scope . module ) {
1057+ this. r . import ( binding, import)
1058+ } else if !this. r . is_builtin_macro ( binding. res ( ) )
1059+ && !this. r . macro_use_prelude . contains_key ( & ident. name )
1060+ {
1061+ // - `!r.is_builtin_macro(res)` excluding the built-in macros such as `Debug` or `Hash`.
1062+ // - `!r.macro_use_prelude.contains_key(name)` excluding macros defined in other extern
1063+ // crates such as `std`.
1064+ // FIXME: This branch should eventually be removed.
1065+ let import = macro_use_import ( this, span, true ) ;
1066+ this. r . import ( binding, import)
1067+ } else {
1068+ return ;
1069+ } ;
10561070 this. add_macro_use_binding ( ident. name , imported_binding, span, allow_shadowing) ;
10571071 }
10581072 } ) ;
@@ -1065,7 +1079,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10651079 & self . parent_scope ,
10661080 ) ;
10671081 if let Ok ( binding) = result {
1068- let import = macro_use_import ( self , ident. span ) ;
1082+ let import = macro_use_import ( self , ident. span , false ) ;
10691083 self . r . potentially_unused_imports . push ( import) ;
10701084 let imported_binding = self . r . import ( binding, import) ;
10711085 self . add_macro_use_binding (
0 commit comments