@@ -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 : Span , warn_not_exported : bool | {
10331033 this. r . arenas . alloc_import ( ImportData {
1034- kind : ImportKind :: MacroUse ,
1034+ kind : ImportKind :: MacroUse { warn_not_exported } ,
10351035 root_id : item. id ,
10361036 parent_scope : this. parent_scope ,
10371037 imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
@@ -1048,11 +1048,28 @@ 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 = if this
1056+ . r
1057+ . is_accessible_from ( binding. vis , this. parent_scope . module )
1058+ {
1059+ this. r . import ( binding, import)
1060+ } else if !this. r . is_builtin_macro ( binding. res ( ) )
1061+ && !this. r . macro_use_prelude . contains_key ( & ident. name )
1062+ {
1063+ // - `!r.is_builtin_macro(res)` excluding the built-in macros such as `Debug` or `Hash`.
1064+ // - `!r.macro_use_prelude.contains_key(name)` excluding macros defined in other extern
1065+ // crates such as `std`.
1066+ // FIXME: This branch should eventually be removed.
1067+ let import = macro_use_import ( this, span, true ) ;
1068+ let binding = this. r . import ( binding, import) ;
1069+ self . r . arenas . alloc_name_binding ( NameBindingData { ..( * binding) . clone ( ) } )
1070+ } else {
1071+ return ;
1072+ } ;
10561073 this. add_macro_use_binding ( ident. name , imported_binding, span, allow_shadowing) ;
10571074 }
10581075 } ) ;
@@ -1065,7 +1082,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10651082 & self . parent_scope ,
10661083 ) ;
10671084 if let Ok ( binding) = result {
1068- let import = macro_use_import ( self , ident. span ) ;
1085+ let import = macro_use_import ( self , ident. span , false ) ;
10691086 self . r . potentially_unused_imports . push ( import) ;
10701087 let imported_binding = self . r . import ( binding, import) ;
10711088 self . add_macro_use_binding (
0 commit comments