@@ -114,7 +114,6 @@ enum Scope<'a> {
114114 CrateRoot ,
115115 Module ( Module < ' a > ) ,
116116 MacroUsePrelude ,
117- BuiltinMacros ,
118117 BuiltinAttrs ,
119118 LegacyPluginHelpers ,
120119 ExternPrelude ,
@@ -1679,7 +1678,7 @@ pub struct Resolver<'a> {
16791678
16801679 crate_loader : & ' a mut CrateLoader < ' a > ,
16811680 macro_names : FxHashSet < Ident > ,
1682- builtin_macros : FxHashMap < Name , & ' a NameBinding < ' a > > ,
1681+ builtin_macros : FxHashMap < Name , SyntaxExtension > ,
16831682 macro_use_prelude : FxHashMap < Name , & ' a NameBinding < ' a > > ,
16841683 pub all_macros : FxHashMap < Name , Res > ,
16851684 macro_map : FxHashMap < DefId , Lrc < SyntaxExtension > > ,
@@ -2021,7 +2020,7 @@ impl<'a> Resolver<'a> {
20212020
20222021 crate_loader,
20232022 macro_names : FxHashSet :: default ( ) ,
2024- builtin_macros : FxHashMap :: default ( ) ,
2023+ builtin_macros : Default :: default ( ) ,
20252024 macro_use_prelude : FxHashMap :: default ( ) ,
20262025 all_macros : FxHashMap :: default ( ) ,
20272026 macro_map : FxHashMap :: default ( ) ,
@@ -2068,6 +2067,11 @@ impl<'a> Resolver<'a> {
20682067 f ( self , MacroNS ) ;
20692068 }
20702069
2070+ fn is_builtin_macro ( & mut self , def_id : Option < DefId > ) -> bool {
2071+ def_id. and_then ( |def_id| self . get_macro_by_def_id ( def_id) )
2072+ . map_or ( false , |ext| ext. is_builtin )
2073+ }
2074+
20712075 fn macro_def ( & self , mut ctxt : SyntaxContext ) -> DefId {
20722076 loop {
20732077 match self . macro_defs . get ( & ctxt. outer_expn ( ) ) {
@@ -2146,7 +2150,7 @@ impl<'a> Resolver<'a> {
21462150 scope_set : ScopeSet ,
21472151 parent_scope : & ParentScope < ' a > ,
21482152 ident : Ident ,
2149- mut visitor : impl FnMut ( & mut Self , Scope < ' a > , Ident ) -> Option < T > ,
2153+ mut visitor : impl FnMut ( & mut Self , Scope < ' a > , /*use_prelude*/ bool , Ident ) -> Option < T > ,
21502154 ) -> Option < T > {
21512155 // General principles:
21522156 // 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -2185,8 +2189,8 @@ impl<'a> Resolver<'a> {
21852189 // 4. `macro_use` prelude (open, the open part is from macro expansions, not controlled).
21862190 // 4a. User-defined prelude from macro-use
21872191 // (open, the open part is from macro expansions, not controlled).
2188- // 4b. Standard library prelude is currently implemented as `macro-use` (closed, controlled)
2189- // 5. Language prelude: builtin macros ( closed, controlled, except for legacy plugins ).
2192+ // 4b. " Standard library prelude" part implemented through `macro-use` (closed, controlled).
2193+ // 4c. Standard library prelude (de-facto closed, controlled).
21902194 // 6. Language prelude: builtin attributes (closed, controlled).
21912195 // 4-6. Legacy plugin helpers (open, not controlled). Similar to derive helpers,
21922196 // but introduced by legacy plugins using `register_attribute`. Priority is somewhere
@@ -2214,17 +2218,16 @@ impl<'a> Resolver<'a> {
22142218 Scope :: CrateRoot => true ,
22152219 Scope :: Module ( ..) => true ,
22162220 Scope :: MacroUsePrelude => use_prelude || rust_2015,
2217- Scope :: BuiltinMacros => true ,
22182221 Scope :: BuiltinAttrs => true ,
22192222 Scope :: LegacyPluginHelpers => use_prelude || rust_2015,
22202223 Scope :: ExternPrelude => use_prelude || is_absolute_path,
22212224 Scope :: ToolPrelude => use_prelude,
2222- Scope :: StdLibPrelude => use_prelude,
2225+ Scope :: StdLibPrelude => use_prelude || ns == MacroNS ,
22232226 Scope :: BuiltinTypes => true ,
22242227 } ;
22252228
22262229 if visit {
2227- if let break_result @ Some ( ..) = visitor ( self , scope, ident) {
2230+ if let break_result @ Some ( ..) = visitor ( self , scope, use_prelude , ident) {
22282231 return break_result;
22292232 }
22302233 }
@@ -2263,7 +2266,6 @@ impl<'a> Resolver<'a> {
22632266 }
22642267 }
22652268 Scope :: MacroUsePrelude => Scope :: StdLibPrelude ,
2266- Scope :: BuiltinMacros => Scope :: BuiltinAttrs ,
22672269 Scope :: BuiltinAttrs => Scope :: LegacyPluginHelpers ,
22682270 Scope :: LegacyPluginHelpers => break , // nowhere else to search
22692271 Scope :: ExternPrelude if is_absolute_path => break ,
@@ -2272,7 +2274,7 @@ impl<'a> Resolver<'a> {
22722274 Scope :: StdLibPrelude => match ns {
22732275 TypeNS => Scope :: BuiltinTypes ,
22742276 ValueNS => break , // nowhere else to search
2275- MacroNS => Scope :: BuiltinMacros ,
2277+ MacroNS => Scope :: BuiltinAttrs ,
22762278 }
22772279 Scope :: BuiltinTypes => break , // nowhere else to search
22782280 } ;
0 commit comments