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