@@ -64,7 +64,7 @@ use diagnostics::{extend_span_to_previous_binding, find_span_of_binding_until_ne
6464use diagnostics:: { ImportSuggestion , LabelSuggestion , Suggestion } ;
6565use imports:: { Import , ImportKind , ImportResolver , NameResolution } ;
6666use late:: { HasGenericParams , PathSource , Rib , RibKind :: * } ;
67- use macros:: { MacroRulesBinding , MacroRulesScope } ;
67+ use macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
6868
6969type Res = def:: Res < NodeId > ;
7070
@@ -100,7 +100,7 @@ impl Determinacy {
100100enum Scope < ' a > {
101101 DeriveHelpers ( ExpnId ) ,
102102 DeriveHelpersCompat ,
103- MacroRules ( MacroRulesScope < ' a > ) ,
103+ MacroRules ( MacroRulesScopeRef < ' a > ) ,
104104 CrateRoot ,
105105 Module ( Module < ' a > ) ,
106106 RegisteredAttrs ,
@@ -133,18 +133,18 @@ enum ScopeSet {
133133pub struct ParentScope < ' a > {
134134 module : Module < ' a > ,
135135 expansion : ExpnId ,
136- macro_rules : MacroRulesScope < ' a > ,
136+ macro_rules : MacroRulesScopeRef < ' a > ,
137137 derives : & ' a [ ast:: Path ] ,
138138}
139139
140140impl < ' a > ParentScope < ' a > {
141141 /// Creates a parent scope with the passed argument used as the module scope component,
142142 /// 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 > {
144144 ParentScope {
145145 module,
146146 expansion : ExpnId :: root ( ) ,
147- macro_rules : MacroRulesScope :: Empty ,
147+ macro_rules : resolver . arenas . alloc_macro_rules_scope ( MacroRulesScope :: Empty ) ,
148148 derives : & [ ] ,
149149 }
150150 }
@@ -974,7 +974,10 @@ pub struct Resolver<'a> {
974974 invocation_parent_scopes : FxHashMap < ExpnId , ParentScope < ' a > > ,
975975 /// `macro_rules` scopes *produced* by expanding the macro invocations,
976976 /// 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 > > > ,
978981 /// Helper attributes that are in scope for the given expansion.
979982 helper_attrs : FxHashMap < ExpnId , Vec < Ident > > ,
980983
@@ -1043,6 +1046,9 @@ impl<'a> ResolverArenas<'a> {
10431046 fn alloc_name_resolution ( & ' a self ) -> & ' a RefCell < NameResolution < ' a > > {
10441047 self . name_resolutions . alloc ( Default :: default ( ) )
10451048 }
1049+ fn alloc_macro_rules_scope ( & ' a self , scope : MacroRulesScope < ' a > ) -> MacroRulesScopeRef < ' a > {
1050+ PtrKey ( self . dropless . alloc ( Cell :: new ( scope) ) )
1051+ }
10461052 fn alloc_macro_rules_binding (
10471053 & ' a self ,
10481054 binding : MacroRulesBinding < ' a > ,
@@ -1230,14 +1236,11 @@ impl<'a> Resolver<'a> {
12301236 let ( registered_attrs, registered_tools) =
12311237 macros:: registered_attrs_and_tools ( session, & krate. attrs ) ;
12321238
1233- let mut invocation_parent_scopes = FxHashMap :: default ( ) ;
1234- invocation_parent_scopes. insert ( ExpnId :: root ( ) , ParentScope :: module ( graph_root) ) ;
1235-
12361239 let features = session. features_untracked ( ) ;
12371240 let non_macro_attr =
12381241 |mark_used| Lrc :: new ( SyntaxExtension :: non_macro_attr ( mark_used, session. edition ( ) ) ) ;
12391242
1240- Resolver {
1243+ let mut resolver = Resolver {
12411244 session,
12421245
12431246 definitions,
@@ -1304,8 +1307,9 @@ impl<'a> Resolver<'a> {
13041307 dummy_ext_bang : Lrc :: new ( SyntaxExtension :: dummy_bang ( session. edition ( ) ) ) ,
13051308 dummy_ext_derive : Lrc :: new ( SyntaxExtension :: dummy_derive ( session. edition ( ) ) ) ,
13061309 non_macro_attrs : [ non_macro_attr ( false ) , non_macro_attr ( true ) ] ,
1307- invocation_parent_scopes,
1310+ invocation_parent_scopes : Default :: default ( ) ,
13081311 output_macro_rules_scopes : Default :: default ( ) ,
1312+ invocation_macro_rules_scopes : Default :: default ( ) ,
13091313 helper_attrs : Default :: default ( ) ,
13101314 local_macro_def_scopes : FxHashMap :: default ( ) ,
13111315 name_already_seen : FxHashMap :: default ( ) ,
@@ -1332,7 +1336,12 @@ impl<'a> Resolver<'a> {
13321336 invocation_parents,
13331337 next_disambiguator : Default :: default ( ) ,
13341338 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
13361345 }
13371346
13381347 pub fn next_node_id ( & mut self ) -> NodeId {
@@ -1702,7 +1711,7 @@ impl<'a> Resolver<'a> {
17021711 }
17031712 Scope :: DeriveHelpers ( ..) => Scope :: DeriveHelpersCompat ,
17041713 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 ( ) {
17061715 MacroRulesScope :: Binding ( binding) => {
17071716 Scope :: MacroRules ( binding. parent_macro_rules_scope )
17081717 }
@@ -3199,7 +3208,7 @@ impl<'a> Resolver<'a> {
31993208 }
32003209 } ;
32013210 let module = self . get_module ( module_id) ;
3202- let parent_scope = & ParentScope :: module ( module) ;
3211+ let parent_scope = & ParentScope :: module ( module, self ) ;
32033212 let res = self . resolve_ast_path ( & path, ns, parent_scope) . map_err ( |_| ( ) ) ?;
32043213 Ok ( ( path, res) )
32053214 }
0 commit comments