@@ -114,7 +114,6 @@ enum Scope<'a> {
114
114
CrateRoot ,
115
115
Module ( Module < ' a > ) ,
116
116
MacroUsePrelude ,
117
- BuiltinMacros ,
118
117
BuiltinAttrs ,
119
118
LegacyPluginHelpers ,
120
119
ExternPrelude ,
@@ -1679,7 +1678,7 @@ pub struct Resolver<'a> {
1679
1678
1680
1679
crate_loader : & ' a mut CrateLoader < ' a > ,
1681
1680
macro_names : FxHashSet < Ident > ,
1682
- builtin_macros : FxHashMap < Name , & ' a NameBinding < ' a > > ,
1681
+ builtin_macros : FxHashMap < Name , SyntaxExtension > ,
1683
1682
macro_use_prelude : FxHashMap < Name , & ' a NameBinding < ' a > > ,
1684
1683
pub all_macros : FxHashMap < Name , Res > ,
1685
1684
macro_map : FxHashMap < DefId , Lrc < SyntaxExtension > > ,
@@ -2021,7 +2020,7 @@ impl<'a> Resolver<'a> {
2021
2020
2022
2021
crate_loader,
2023
2022
macro_names : FxHashSet :: default ( ) ,
2024
- builtin_macros : FxHashMap :: default ( ) ,
2023
+ builtin_macros : Default :: default ( ) ,
2025
2024
macro_use_prelude : FxHashMap :: default ( ) ,
2026
2025
all_macros : FxHashMap :: default ( ) ,
2027
2026
macro_map : FxHashMap :: default ( ) ,
@@ -2068,6 +2067,11 @@ impl<'a> Resolver<'a> {
2068
2067
f ( self , MacroNS ) ;
2069
2068
}
2070
2069
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
+
2071
2075
fn macro_def ( & self , mut ctxt : SyntaxContext ) -> DefId {
2072
2076
loop {
2073
2077
match self . macro_defs . get ( & ctxt. outer_expn ( ) ) {
@@ -2146,7 +2150,7 @@ impl<'a> Resolver<'a> {
2146
2150
scope_set : ScopeSet ,
2147
2151
parent_scope : & ParentScope < ' a > ,
2148
2152
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 > ,
2150
2154
) -> Option < T > {
2151
2155
// General principles:
2152
2156
// 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -2185,8 +2189,8 @@ impl<'a> Resolver<'a> {
2185
2189
// 4. `macro_use` prelude (open, the open part is from macro expansions, not controlled).
2186
2190
// 4a. User-defined prelude from macro-use
2187
2191
// (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).
2190
2194
// 6. Language prelude: builtin attributes (closed, controlled).
2191
2195
// 4-6. Legacy plugin helpers (open, not controlled). Similar to derive helpers,
2192
2196
// but introduced by legacy plugins using `register_attribute`. Priority is somewhere
@@ -2214,17 +2218,16 @@ impl<'a> Resolver<'a> {
2214
2218
Scope :: CrateRoot => true ,
2215
2219
Scope :: Module ( ..) => true ,
2216
2220
Scope :: MacroUsePrelude => use_prelude || rust_2015,
2217
- Scope :: BuiltinMacros => true ,
2218
2221
Scope :: BuiltinAttrs => true ,
2219
2222
Scope :: LegacyPluginHelpers => use_prelude || rust_2015,
2220
2223
Scope :: ExternPrelude => use_prelude || is_absolute_path,
2221
2224
Scope :: ToolPrelude => use_prelude,
2222
- Scope :: StdLibPrelude => use_prelude,
2225
+ Scope :: StdLibPrelude => use_prelude || ns == MacroNS ,
2223
2226
Scope :: BuiltinTypes => true ,
2224
2227
} ;
2225
2228
2226
2229
if visit {
2227
- if let break_result @ Some ( ..) = visitor ( self , scope, ident) {
2230
+ if let break_result @ Some ( ..) = visitor ( self , scope, use_prelude , ident) {
2228
2231
return break_result;
2229
2232
}
2230
2233
}
@@ -2263,7 +2266,6 @@ impl<'a> Resolver<'a> {
2263
2266
}
2264
2267
}
2265
2268
Scope :: MacroUsePrelude => Scope :: StdLibPrelude ,
2266
- Scope :: BuiltinMacros => Scope :: BuiltinAttrs ,
2267
2269
Scope :: BuiltinAttrs => Scope :: LegacyPluginHelpers ,
2268
2270
Scope :: LegacyPluginHelpers => break , // nowhere else to search
2269
2271
Scope :: ExternPrelude if is_absolute_path => break ,
@@ -2272,7 +2274,7 @@ impl<'a> Resolver<'a> {
2272
2274
Scope :: StdLibPrelude => match ns {
2273
2275
TypeNS => Scope :: BuiltinTypes ,
2274
2276
ValueNS => break , // nowhere else to search
2275
- MacroNS => Scope :: BuiltinMacros ,
2277
+ MacroNS => Scope :: BuiltinAttrs ,
2276
2278
}
2277
2279
Scope :: BuiltinTypes => break , // nowhere else to search
2278
2280
} ;
0 commit comments