@@ -64,7 +64,7 @@ use diagnostics::{extend_span_to_previous_binding, find_span_of_binding_until_ne
64
64
use diagnostics:: { ImportSuggestion , LabelSuggestion , Suggestion } ;
65
65
use imports:: { Import , ImportKind , ImportResolver , NameResolution } ;
66
66
use late:: { HasGenericParams , PathSource , Rib , RibKind :: * } ;
67
- use macros:: { MacroRulesBinding , MacroRulesScope } ;
67
+ use macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
68
68
69
69
type Res = def:: Res < NodeId > ;
70
70
@@ -100,7 +100,7 @@ impl Determinacy {
100
100
enum Scope < ' a > {
101
101
DeriveHelpers ( ExpnId ) ,
102
102
DeriveHelpersCompat ,
103
- MacroRules ( MacroRulesScope < ' a > ) ,
103
+ MacroRules ( MacroRulesScopeRef < ' a > ) ,
104
104
CrateRoot ,
105
105
Module ( Module < ' a > ) ,
106
106
RegisteredAttrs ,
@@ -133,18 +133,18 @@ enum ScopeSet {
133
133
pub struct ParentScope < ' a > {
134
134
module : Module < ' a > ,
135
135
expansion : ExpnId ,
136
- macro_rules : MacroRulesScope < ' a > ,
136
+ macro_rules : MacroRulesScopeRef < ' a > ,
137
137
derives : & ' a [ ast:: Path ] ,
138
138
}
139
139
140
140
impl < ' a > ParentScope < ' a > {
141
141
/// Creates a parent scope with the passed argument used as the module scope component,
142
142
/// and other scope components set to default empty values.
143
- pub fn module ( module : Module < ' a > ) -> ParentScope < ' a > {
143
+ pub fn module ( module : Module < ' a > , resolver : & Resolver < ' a > ) -> ParentScope < ' a > {
144
144
ParentScope {
145
145
module,
146
146
expansion : ExpnId :: root ( ) ,
147
- macro_rules : MacroRulesScope :: Empty ,
147
+ macro_rules : resolver . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Empty ) ,
148
148
derives : & [ ] ,
149
149
}
150
150
}
@@ -974,7 +974,10 @@ pub struct Resolver<'a> {
974
974
invocation_parent_scopes : FxHashMap < ExpnId , ParentScope < ' a > > ,
975
975
/// `macro_rules` scopes *produced* by expanding the macro invocations,
976
976
/// include all the `macro_rules` items and other invocations generated by them.
977
- output_macro_rules_scopes : FxHashMap < ExpnId , MacroRulesScope < ' a > > ,
977
+ output_macro_rules_scopes : FxHashMap < ExpnId , MacroRulesScopeRef < ' a > > ,
978
+ /// References to all `MacroRulesScope::Invocation(invoc_id)`s, used to update such scopes
979
+ /// when their corresponding `invoc_id`s get expanded.
980
+ invocation_macro_rules_scopes : FxHashMap < ExpnId , FxHashSet < MacroRulesScopeRef < ' a > > > ,
978
981
/// Helper attributes that are in scope for the given expansion.
979
982
helper_attrs : FxHashMap < ExpnId , Vec < Ident > > ,
980
983
@@ -1043,6 +1046,9 @@ impl<'a> ResolverArenas<'a> {
1043
1046
fn alloc_name_resolution ( & ' a self ) -> & ' a RefCell < NameResolution < ' a > > {
1044
1047
self . name_resolutions . alloc ( Default :: default ( ) )
1045
1048
}
1049
+ fn alloc_macro_rules_scope ( & ' a self , scope : MacroRulesScope < ' a > ) -> MacroRulesScopeRef < ' a > {
1050
+ PtrKey ( self . dropless . alloc ( Cell :: new ( scope) ) )
1051
+ }
1046
1052
fn alloc_macro_rules_binding (
1047
1053
& ' a self ,
1048
1054
binding : MacroRulesBinding < ' a > ,
@@ -1230,14 +1236,11 @@ impl<'a> Resolver<'a> {
1230
1236
let ( registered_attrs, registered_tools) =
1231
1237
macros:: registered_attrs_and_tools ( session, & krate. attrs ) ;
1232
1238
1233
- let mut invocation_parent_scopes = FxHashMap :: default ( ) ;
1234
- invocation_parent_scopes. insert ( ExpnId :: root ( ) , ParentScope :: module ( graph_root) ) ;
1235
-
1236
1239
let features = session. features_untracked ( ) ;
1237
1240
let non_macro_attr =
1238
1241
|mark_used| Lrc :: new ( SyntaxExtension :: non_macro_attr ( mark_used, session. edition ( ) ) ) ;
1239
1242
1240
- Resolver {
1243
+ let mut resolver = Resolver {
1241
1244
session,
1242
1245
1243
1246
definitions,
@@ -1304,8 +1307,9 @@ impl<'a> Resolver<'a> {
1304
1307
dummy_ext_bang : Lrc :: new ( SyntaxExtension :: dummy_bang ( session. edition ( ) ) ) ,
1305
1308
dummy_ext_derive : Lrc :: new ( SyntaxExtension :: dummy_derive ( session. edition ( ) ) ) ,
1306
1309
non_macro_attrs : [ non_macro_attr ( false ) , non_macro_attr ( true ) ] ,
1307
- invocation_parent_scopes,
1310
+ invocation_parent_scopes : Default :: default ( ) ,
1308
1311
output_macro_rules_scopes : Default :: default ( ) ,
1312
+ invocation_macro_rules_scopes : Default :: default ( ) ,
1309
1313
helper_attrs : Default :: default ( ) ,
1310
1314
local_macro_def_scopes : FxHashMap :: default ( ) ,
1311
1315
name_already_seen : FxHashMap :: default ( ) ,
@@ -1332,7 +1336,12 @@ impl<'a> Resolver<'a> {
1332
1336
invocation_parents,
1333
1337
next_disambiguator : Default :: default ( ) ,
1334
1338
trait_impl_items : Default :: default ( ) ,
1335
- }
1339
+ } ;
1340
+
1341
+ let root_parent_scope = ParentScope :: module ( graph_root, & resolver) ;
1342
+ resolver. invocation_parent_scopes . insert ( ExpnId :: root ( ) , root_parent_scope) ;
1343
+
1344
+ resolver
1336
1345
}
1337
1346
1338
1347
pub fn next_node_id ( & mut self ) -> NodeId {
@@ -1702,7 +1711,7 @@ impl<'a> Resolver<'a> {
1702
1711
}
1703
1712
Scope :: DeriveHelpers ( ..) => Scope :: DeriveHelpersCompat ,
1704
1713
Scope :: DeriveHelpersCompat => Scope :: MacroRules ( parent_scope. macro_rules ) ,
1705
- Scope :: MacroRules ( macro_rules_scope) => match macro_rules_scope {
1714
+ Scope :: MacroRules ( macro_rules_scope) => match macro_rules_scope. get ( ) {
1706
1715
MacroRulesScope :: Binding ( binding) => {
1707
1716
Scope :: MacroRules ( binding. parent_macro_rules_scope )
1708
1717
}
@@ -3199,7 +3208,7 @@ impl<'a> Resolver<'a> {
3199
3208
}
3200
3209
} ;
3201
3210
let module = self . get_module ( module_id) ;
3202
- let parent_scope = & ParentScope :: module ( module) ;
3211
+ let parent_scope = & ParentScope :: module ( module, self ) ;
3203
3212
let res = self . resolve_ast_path ( & path, ns, parent_scope) . map_err ( |_| ( ) ) ?;
3204
3213
Ok ( ( path, res) )
3205
3214
}
0 commit comments