@@ -1029,9 +1029,9 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1029
1029
}
1030
1030
}
1031
1031
1032
- let macro_use_import = |this : & Self , span| {
1032
+ let macro_use_import = |this : & Self , span, warn_private | {
1033
1033
this. r . arenas . alloc_import ( ImportData {
1034
- kind : ImportKind :: MacroUse ,
1034
+ kind : ImportKind :: MacroUse { warn_private } ,
1035
1035
root_id : item. id ,
1036
1036
parent_scope : this. parent_scope ,
1037
1037
imported_module : Cell :: new ( Some ( ModuleOrUniformRoot :: Module ( module) ) ) ,
@@ -1048,11 +1048,25 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1048
1048
1049
1049
let allow_shadowing = self . parent_scope . expansion == LocalExpnId :: ROOT ;
1050
1050
if let Some ( span) = import_all {
1051
- let import = macro_use_import ( self , span) ;
1051
+ let import = macro_use_import ( self , span, false ) ;
1052
1052
self . r . potentially_unused_imports . push ( import) ;
1053
1053
module. for_each_child ( self , |this, ident, ns, binding| {
1054
1054
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
+ } ;
1056
1070
this. add_macro_use_binding ( ident. name , imported_binding, span, allow_shadowing) ;
1057
1071
}
1058
1072
} ) ;
@@ -1065,7 +1079,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1065
1079
& self . parent_scope ,
1066
1080
) ;
1067
1081
if let Ok ( binding) = result {
1068
- let import = macro_use_import ( self , ident. span ) ;
1082
+ let import = macro_use_import ( self , ident. span , false ) ;
1069
1083
self . r . potentially_unused_imports . push ( import) ;
1070
1084
let imported_binding = self . r . import ( binding, import) ;
1071
1085
self . add_macro_use_binding (
0 commit comments