@@ -140,11 +140,23 @@ impl<'a> base::Resolver for Resolver<'a> {
140
140
ImportResolver { r : self } . resolve_imports ( )
141
141
}
142
142
143
- fn resolve_macro_invocation ( & mut self , invoc : & Invocation , invoc_id : ExpnId , force : bool )
144
- -> Result < Option < Lrc < SyntaxExtension > > , Indeterminate > {
145
- let inherited_parent_scope = self . invocation_parent_scopes [ & invoc_id] ;
146
- let parent_scope = * self . invocation_parent_scopes . entry ( invoc. expansion_data . id )
147
- . or_insert ( inherited_parent_scope) ;
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
+
148
160
let ( path, kind, derives, after_derive) = match invoc. kind {
149
161
InvocationKind :: Attr { ref attr, ref derives, after_derive, .. } =>
150
162
( & attr. path , MacroKind :: Attr , self . arenas . alloc_ast_paths ( derives) , after_derive) ,
@@ -163,7 +175,7 @@ impl<'a> base::Resolver for Resolver<'a> {
163
175
match self . resolve_macro_path ( path, Some ( MacroKind :: Derive ) ,
164
176
& parent_scope, true , force) {
165
177
Ok ( ( Some ( ref ext) , _) ) if ext. is_derive_copy => {
166
- self . add_derives ( invoc . expansion_data . id , SpecialDerives :: COPY ) ;
178
+ self . add_derives ( invoc_id , SpecialDerives :: COPY ) ;
167
179
return Ok ( None ) ;
168
180
}
169
181
Err ( Determinacy :: Undetermined ) => result = Err ( Indeterminate ) ,
@@ -180,19 +192,15 @@ impl<'a> base::Resolver for Resolver<'a> {
180
192
let ( ext, res) = self . smart_resolve_macro_path ( path, kind, parent_scope, force) ?;
181
193
182
194
let span = invoc. span ( ) ;
183
- invoc. expansion_data . id . set_expn_data (
184
- ext. expn_data ( parent_scope. expansion , span, fast_print_path ( path) )
185
- ) ;
195
+ invoc_id. set_expn_data ( ext. expn_data ( parent_scope. expansion , span, fast_print_path ( path) ) ) ;
186
196
187
197
if let Res :: Def ( _, def_id) = res {
188
198
if after_derive {
189
199
self . session . span_err ( span, "macro attributes must be placed before `#[derive]`" ) ;
190
200
}
191
- self . macro_defs . insert ( invoc. expansion_data . id , def_id) ;
192
- let normal_module_def_id =
193
- self . macro_def_scope ( invoc. expansion_data . id ) . normal_ancestor_id ;
194
- self . definitions . add_parent_module_of_macro_def ( invoc. expansion_data . id ,
195
- 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) ;
196
204
}
197
205
198
206
Ok ( Some ( ext) )
0 commit comments