Skip to content

Commit 96032aa

Browse files
committed
expand: Keep the correct current expansion ID for eager expansions
Solve the problem of `ParentScope` entries for eager expansions not exising in the resolver map by creating them on demand.
1 parent 1dd56aa commit 96032aa

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

src/librustc_resolve/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ impl<'a> base::Resolver for Resolver<'a> {
142142

143143
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, force: bool)
144144
-> Result<Option<Lrc<SyntaxExtension>>, Indeterminate> {
145-
let parent_scope = self.invocation_parent_scopes[&invoc_id];
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);
146148
let (path, kind, derives, after_derive) = match invoc.kind {
147149
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
148150
(&attr.path, MacroKind::Attr, self.arenas.alloc_ast_paths(derives), after_derive),

src/libsyntax/ext/expand.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
318318
progress = true;
319319
let ExpansionData { depth, id: expn_id, .. } = invoc.expansion_data;
320320
self.cx.current_expansion = invoc.expansion_data.clone();
321-
self.cx.current_expansion.id = scope;
322321

323322
// FIXME(jseyfried): Refactor out the following logic
324323
let (expanded_fragment, new_invocations) = if let Some(ext) = ext {

src/test/ui/hygiene/eager-from-opaque.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: cannot find macro `foo!` in this scope
33
|
44
LL | foo!()
55
| ^^^
6+
...
7+
LL | format_args!(bar!());
8+
| ------ in this macro invocation
69

710
error: aborting due to previous error
811

src/test/ui/macros/derive-in-eager-expansion-hang.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ LL | |
88
LL | | ""
99
LL | | }
1010
| |_____^
11+
...
12+
LL | format_args!(hang!());
13+
| ------- in this macro invocation
1114
help: you might be missing a string literal to format with
1215
|
1316
LL | format_args!("{}", hang!());

0 commit comments

Comments
 (0)