@@ -976,9 +976,6 @@ pub struct Resolver<'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
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 > > > ,
982
979
/// Helper attributes that are in scope for the given expansion.
983
980
helper_attrs : FxHashMap < ExpnId , Vec < Ident > > ,
984
981
@@ -1310,7 +1307,6 @@ impl<'a> Resolver<'a> {
1310
1307
non_macro_attrs : [ non_macro_attr ( false ) , non_macro_attr ( true ) ] ,
1311
1308
invocation_parent_scopes : Default :: default ( ) ,
1312
1309
output_macro_rules_scopes : Default :: default ( ) ,
1313
- invocation_macro_rules_scopes : Default :: default ( ) ,
1314
1310
helper_attrs : Default :: default ( ) ,
1315
1311
local_macro_def_scopes : FxHashMap :: default ( ) ,
1316
1312
name_already_seen : FxHashMap :: default ( ) ,
@@ -1680,7 +1676,20 @@ impl<'a> Resolver<'a> {
1680
1676
!( expn_id == parent_scope. expansion && macro_kind == Some ( MacroKind :: Derive ) )
1681
1677
}
1682
1678
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
+ }
1684
1693
Scope :: CrateRoot => true ,
1685
1694
Scope :: Module ( ..) => true ,
1686
1695
Scope :: RegisteredAttrs => use_prelude,
@@ -1716,11 +1725,9 @@ impl<'a> Resolver<'a> {
1716
1725
MacroRulesScope :: Binding ( binding) => {
1717
1726
Scope :: MacroRules ( binding. parent_macro_rules_scope )
1718
1727
}
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
+ }
1724
1731
MacroRulesScope :: Empty => Scope :: Module ( module) ,
1725
1732
} ,
1726
1733
Scope :: CrateRoot => match ns {
0 commit comments