Skip to content

Commit

Permalink
Fixup directory ownership offsets during expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
cramertj committed Nov 6, 2018
1 parent 4463132 commit 561642c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,13 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
return noop_fold_item(item, self);
}

// If the directory ownership is replaced, this var
// holds the original so that it can be swapped back in.
let mut orig_directory_ownership = None;
// If the directory ownership `relative` field was appended to,
// this bool is `true` so that it can be popped at the end.
let mut directory_ownership_needs_pop = false;

let mut module = (*self.cx.current_expansion.module).clone();
module.mod_path.push(item.ident);

Expand All @@ -1356,9 +1362,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {

if inline_module {
if let DirectoryOwnership::Owned { relative } =
&mut self.directory.ownership
&mut self.cx.current_expansion.directory_ownership
{
relative.push(item.ident);
directory_ownership_needs_pop = true;
}
} else {
let path = self.cx.parse_sess.source_map().span_to_unmapped_path(inner);
Expand All @@ -1383,11 +1390,21 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {

let orig_module =
mem::replace(&mut self.cx.current_expansion.module, Rc::new(module));

let result = noop_fold_item(item, self);

// Clean up, restoring all replaced or mutated expansion state.
self.cx.current_expansion.module = orig_module;
if let Some(orig_directory_ownership) = orig_directory_ownership {
self.cx.current_expansion.directory_ownership = orig_directory_ownership;
}
if directory_ownership_needs_pop {
if let DirectoryOwnership::Owned { relative } =
&mut self.cx.current_expansion.directory_ownership
{
relative.pop();
}
}
result
}

Expand Down

0 comments on commit 561642c

Please sign in to comment.