@@ -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 : Span , warn_not_exported : bool | {
1033
1033
this. r . arenas . alloc_import ( ImportData {
1034
- kind : ImportKind :: MacroUse ,
1034
+ kind : ImportKind :: MacroUse { warn_not_exported } ,
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,28 @@ 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 = 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
+ } ;
1056
1073
this. add_macro_use_binding ( ident. name , imported_binding, span, allow_shadowing) ;
1057
1074
}
1058
1075
} ) ;
@@ -1065,7 +1082,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
1065
1082
& self . parent_scope ,
1066
1083
) ;
1067
1084
if let Ok ( binding) = result {
1068
- let import = macro_use_import ( self , ident. span ) ;
1085
+ let import = macro_use_import ( self , ident. span , false ) ;
1069
1086
self . r . potentially_unused_imports . push ( import) ;
1070
1087
let imported_binding = self . r . import ( binding, import) ;
1071
1088
self . add_macro_use_binding (
0 commit comments