Skip to content

Commit

Permalink
expand: Keep the correct current expansion ID for eager expansions
Browse files Browse the repository at this point in the history
Solve the problem of `ParentScope` entries for eager expansions not exising in the resolver map by creating them on demand.
  • Loading branch information
petrochenkov committed Aug 21, 2019
1 parent 1dd56aa commit 96032aa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/librustc_resolve/macros.rs
Expand Up @@ -142,7 +142,9 @@ impl<'a> base::Resolver for Resolver<'a> {

fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, force: bool)
-> Result<Option<Lrc<SyntaxExtension>>, Indeterminate> {
let parent_scope = self.invocation_parent_scopes[&invoc_id];
let inherited_parent_scope = self.invocation_parent_scopes[&invoc_id];
let parent_scope = *self.invocation_parent_scopes.entry(invoc.expansion_data.id)
.or_insert(inherited_parent_scope);
let (path, kind, derives, after_derive) = match invoc.kind {
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
(&attr.path, MacroKind::Attr, self.arenas.alloc_ast_paths(derives), after_derive),
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/expand.rs
Expand Up @@ -318,7 +318,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
progress = true;
let ExpansionData { depth, id: expn_id, .. } = invoc.expansion_data;
self.cx.current_expansion = invoc.expansion_data.clone();
self.cx.current_expansion.id = scope;

// FIXME(jseyfried): Refactor out the following logic
let (expanded_fragment, new_invocations) = if let Some(ext) = ext {
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/hygiene/eager-from-opaque.stderr
Expand Up @@ -3,6 +3,9 @@ error: cannot find macro `foo!` in this scope
|
LL | foo!()
| ^^^
...
LL | format_args!(bar!());
| ------ in this macro invocation

error: aborting due to previous error

3 changes: 3 additions & 0 deletions src/test/ui/macros/derive-in-eager-expansion-hang.stderr
Expand Up @@ -8,6 +8,9 @@ LL | |
LL | | ""
LL | | }
| |_____^
...
LL | format_args!(hang!());
| ------- in this macro invocation
help: you might be missing a string literal to format with
|
LL | format_args!("{}", hang!());
Expand Down

0 comments on commit 96032aa

Please sign in to comment.