@@ -140,9 +140,23 @@ impl<'a> base::Resolver for Resolver<'a> {
140140        ImportResolver  {  r :  self  } . resolve_imports ( ) 
141141    } 
142142
143-     fn  resolve_macro_invocation ( & mut  self ,  invoc :  & Invocation ,  invoc_id :  ExpnId ,  force :  bool ) 
144-                                 -> Result < Option < Lrc < SyntaxExtension > > ,  Indeterminate >  { 
145-         let  parent_scope = self . invocation_parent_scopes [ & invoc_id] ; 
143+     fn  resolve_macro_invocation ( 
144+         & mut  self ,  invoc :  & Invocation ,  eager_expansion_root :  ExpnId ,  force :  bool 
145+     )  -> Result < Option < Lrc < SyntaxExtension > > ,  Indeterminate >  { 
146+         let  invoc_id = invoc. expansion_data . id ; 
147+         let  parent_scope = match  self . invocation_parent_scopes . get ( & invoc_id)  { 
148+             Some ( parent_scope)  => * parent_scope, 
149+             None  => { 
150+                 // If there's no entry in the table, then we are resolving an eagerly expanded 
151+                 // macro, which should inherit its parent scope from its eager expansion root - 
152+                 // the macro that requested this eager expansion. 
153+                 let  parent_scope = * self . invocation_parent_scopes . get ( & eager_expansion_root) 
154+                     . expect ( "non-eager expansion without a parent scope" ) ; 
155+                 self . invocation_parent_scopes . insert ( invoc_id,  parent_scope) ; 
156+                 parent_scope
157+             } 
158+         } ; 
159+ 
146160        let  ( path,  kind,  derives,  after_derive)  = match  invoc. kind  { 
147161            InvocationKind :: Attr  {  ref  attr,  ref  derives,  after_derive,  .. }  =>
148162                ( & attr. path ,  MacroKind :: Attr ,  self . arenas . alloc_ast_paths ( derives) ,  after_derive) , 
@@ -161,7 +175,7 @@ impl<'a> base::Resolver for Resolver<'a> {
161175                        match  self . resolve_macro_path ( path,  Some ( MacroKind :: Derive ) , 
162176                                                      & parent_scope,  true ,  force)  { 
163177                            Ok ( ( Some ( ref  ext) ,  _) )  if  ext. is_derive_copy  => { 
164-                                 self . add_derives ( invoc . expansion_data . id ,  SpecialDerives :: COPY ) ; 
178+                                 self . add_derives ( invoc_id ,  SpecialDerives :: COPY ) ; 
165179                                return  Ok ( None ) ; 
166180                            } 
167181                            Err ( Determinacy :: Undetermined )  => result = Err ( Indeterminate ) , 
@@ -178,19 +192,15 @@ impl<'a> base::Resolver for Resolver<'a> {
178192        let  ( ext,  res)  = self . smart_resolve_macro_path ( path,  kind,  parent_scope,  force) ?; 
179193
180194        let  span = invoc. span ( ) ; 
181-         invoc. expansion_data . id . set_expn_data ( 
182-             ext. expn_data ( parent_scope. expansion ,  span,  fast_print_path ( path) ) 
183-         ) ; 
195+         invoc_id. set_expn_data ( ext. expn_data ( parent_scope. expansion ,  span,  fast_print_path ( path) ) ) ; 
184196
185197        if  let  Res :: Def ( _,  def_id)  = res { 
186198            if  after_derive { 
187199                self . session . span_err ( span,  "macro attributes must be placed before `#[derive]`" ) ; 
188200            } 
189-             self . macro_defs . insert ( invoc. expansion_data . id ,  def_id) ; 
190-             let  normal_module_def_id =
191-                 self . macro_def_scope ( invoc. expansion_data . id ) . normal_ancestor_id ; 
192-             self . definitions . add_parent_module_of_macro_def ( invoc. expansion_data . id , 
193-                                                             normal_module_def_id) ; 
201+             self . macro_defs . insert ( invoc_id,  def_id) ; 
202+             let  normal_module_def_id = self . macro_def_scope ( invoc_id) . normal_ancestor_id ; 
203+             self . definitions . add_parent_module_of_macro_def ( invoc_id,  normal_module_def_id) ; 
194204        } 
195205
196206        Ok ( Some ( ext) ) 
0 commit comments