@@ -15,6 +15,7 @@ use codemap::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan};
15
15
use config:: { is_test_or_bench, StripUnconfigured } ;
16
16
use errors:: { Applicability , FatalError } ;
17
17
use ext:: base:: * ;
18
+ use ext:: build:: AstBuilder ;
18
19
use ext:: derive:: { add_derived_markers, collect_derives} ;
19
20
use ext:: hygiene:: { self , Mark , SyntaxContext } ;
20
21
use ext:: placeholders:: { placeholder, PlaceholderExpander } ;
@@ -1354,12 +1355,29 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1354
1355
// Ensure that test functions are accessible from the test harness.
1355
1356
ast:: ItemKind :: Fn ( ..) if self . cx . ecfg . should_test => {
1356
1357
if item. attrs . iter ( ) . any ( |attr| is_test_or_bench ( attr) ) {
1358
+ let orig_vis = item. vis . clone ( ) ;
1359
+
1360
+ // Publicize the item under gensymed name to avoid pollution
1357
1361
item = item. map ( |mut item| {
1358
1362
item. vis = respan ( item. vis . span , ast:: VisibilityKind :: Public ) ;
1363
+ item. ident = Ident :: from_interned_str (
1364
+ item. ident . as_interned_str ( ) ) . gensym ( ) ;
1359
1365
item
1360
1366
} ) ;
1367
+
1368
+ // Use the gensymed name under the item's original visibility
1369
+ let use_item = self . cx . item_use_simple_ (
1370
+ item. ident . span ,
1371
+ orig_vis,
1372
+ Some ( Ident :: from_interned_str ( item. ident . as_interned_str ( ) ) ) ,
1373
+ self . cx . path ( item. ident . span , vec ! [ item. ident] ) ) ;
1374
+
1375
+ SmallVector :: many (
1376
+ noop_fold_item ( item, self ) . into_iter ( )
1377
+ . chain ( noop_fold_item ( use_item, self ) ) )
1378
+ } else {
1379
+ noop_fold_item ( item, self )
1361
1380
}
1362
- noop_fold_item ( item, self )
1363
1381
}
1364
1382
_ => noop_fold_item ( item, self ) ,
1365
1383
}
0 commit comments