Skip to content

Commit 561642c

Browse files
committed
Fixup directory ownership offsets during expansion
1 parent 4463132 commit 561642c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/libsyntax/ext/expand.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,13 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
13451345
return noop_fold_item(item, self);
13461346
}
13471347

1348+
// If the directory ownership is replaced, this var
1349+
// holds the original so that it can be swapped back in.
13481350
let mut orig_directory_ownership = None;
1351+
// If the directory ownership `relative` field was appended to,
1352+
// this bool is `true` so that it can be popped at the end.
1353+
let mut directory_ownership_needs_pop = false;
1354+
13491355
let mut module = (*self.cx.current_expansion.module).clone();
13501356
module.mod_path.push(item.ident);
13511357

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

13571363
if inline_module {
13581364
if let DirectoryOwnership::Owned { relative } =
1359-
&mut self.directory.ownership
1365+
&mut self.cx.current_expansion.directory_ownership
13601366
{
13611367
relative.push(item.ident);
1368+
directory_ownership_needs_pop = true;
13621369
}
13631370
} else {
13641371
let path = self.cx.parse_sess.source_map().span_to_unmapped_path(inner);
@@ -1383,11 +1390,21 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
13831390

13841391
let orig_module =
13851392
mem::replace(&mut self.cx.current_expansion.module, Rc::new(module));
1393+
13861394
let result = noop_fold_item(item, self);
1395+
1396+
// Clean up, restoring all replaced or mutated expansion state.
13871397
self.cx.current_expansion.module = orig_module;
13881398
if let Some(orig_directory_ownership) = orig_directory_ownership {
13891399
self.cx.current_expansion.directory_ownership = orig_directory_ownership;
13901400
}
1401+
if directory_ownership_needs_pop {
1402+
if let DirectoryOwnership::Owned { relative } =
1403+
&mut self.cx.current_expansion.directory_ownership
1404+
{
1405+
relative.pop();
1406+
}
1407+
}
13911408
result
13921409
}
13931410

0 commit comments

Comments
 (0)