@@ -976,9 +976,6 @@ pub struct Resolver<'a> {
976976 /// `macro_rules` scopes *produced* by expanding the macro invocations,
977977 /// include all the `macro_rules` items and other invocations generated by them.
978978 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 > > > ,
982979 /// Helper attributes that are in scope for the given expansion.
983980 helper_attrs : FxHashMap < ExpnId , Vec < Ident > > ,
984981
@@ -1310,7 +1307,6 @@ impl<'a> Resolver<'a> {
13101307 non_macro_attrs : [ non_macro_attr ( false ) , non_macro_attr ( true ) ] ,
13111308 invocation_parent_scopes : Default :: default ( ) ,
13121309 output_macro_rules_scopes : Default :: default ( ) ,
1313- invocation_macro_rules_scopes : Default :: default ( ) ,
13141310 helper_attrs : Default :: default ( ) ,
13151311 local_macro_def_scopes : FxHashMap :: default ( ) ,
13161312 name_already_seen : FxHashMap :: default ( ) ,
@@ -1680,7 +1676,20 @@ impl<'a> Resolver<'a> {
16801676 !( expn_id == parent_scope. expansion && macro_kind == Some ( MacroKind :: Derive ) )
16811677 }
16821678 Scope :: DeriveHelpersCompat => true ,
1683- Scope :: MacroRules ( ..) => true ,
1679+ Scope :: MacroRules ( macro_rules_scope) => {
1680+ // Use "path compression" on `macro_rules` scope chains. This is an optimization
1681+ // used to avoid long scope chains, see the comments on `MacroRulesScopeRef`.
1682+ // As another consequence of this optimization visitors never observe invocation
1683+ // scopes for macros that were already expanded.
1684+ while let MacroRulesScope :: Invocation ( invoc_id) = macro_rules_scope. get ( ) {
1685+ if let Some ( next_scope) = self . output_macro_rules_scopes . get ( & invoc_id) {
1686+ macro_rules_scope. set ( next_scope. get ( ) ) ;
1687+ } else {
1688+ break ;
1689+ }
1690+ }
1691+ true
1692+ }
16841693 Scope :: CrateRoot => true ,
16851694 Scope :: Module ( ..) => true ,
16861695 Scope :: RegisteredAttrs => use_prelude,
@@ -1716,11 +1725,9 @@ impl<'a> Resolver<'a> {
17161725 MacroRulesScope :: Binding ( binding) => {
17171726 Scope :: MacroRules ( binding. parent_macro_rules_scope )
17181727 }
1719- MacroRulesScope :: Invocation ( invoc_id) => Scope :: MacroRules (
1720- self . output_macro_rules_scopes . get ( & invoc_id) . cloned ( ) . unwrap_or_else (
1721- || self . invocation_parent_scopes [ & invoc_id] . macro_rules ,
1722- ) ,
1723- ) ,
1728+ MacroRulesScope :: Invocation ( invoc_id) => {
1729+ Scope :: MacroRules ( self . invocation_parent_scopes [ & invoc_id] . macro_rules )
1730+ }
17241731 MacroRulesScope :: Empty => Scope :: Module ( module) ,
17251732 } ,
17261733 Scope :: CrateRoot => match ns {
0 commit comments