@@ -1345,7 +1345,13 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1345
1345
return noop_fold_item ( item, self ) ;
1346
1346
}
1347
1347
1348
+ // If the directory ownership is replaced, this var
1349
+ // holds the original so that it can be swapped back in.
1348
1350
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
+
1349
1355
let mut module = ( * self . cx . current_expansion . module ) . clone ( ) ;
1350
1356
module. mod_path . push ( item. ident ) ;
1351
1357
@@ -1356,9 +1362,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1356
1362
1357
1363
if inline_module {
1358
1364
if let DirectoryOwnership :: Owned { relative } =
1359
- & mut self . directory . ownership
1365
+ & mut self . cx . current_expansion . directory_ownership
1360
1366
{
1361
1367
relative. push ( item. ident ) ;
1368
+ directory_ownership_needs_pop = true ;
1362
1369
}
1363
1370
} else {
1364
1371
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> {
1383
1390
1384
1391
let orig_module =
1385
1392
mem:: replace ( & mut self . cx . current_expansion . module , Rc :: new ( module) ) ;
1393
+
1386
1394
let result = noop_fold_item ( item, self ) ;
1395
+
1396
+ // Clean up, restoring all replaced or mutated expansion state.
1387
1397
self . cx . current_expansion . module = orig_module;
1388
1398
if let Some ( orig_directory_ownership) = orig_directory_ownership {
1389
1399
self . cx . current_expansion . directory_ownership = orig_directory_ownership;
1390
1400
}
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
+ }
1391
1408
result
1392
1409
}
1393
1410
0 commit comments