@@ -12,10 +12,9 @@ use ast::{self, Block, Ident, NodeId, PatKind, Path};
12
12
use ast:: { MacStmtStyle , StmtKind , ItemKind } ;
13
13
use attr:: { self , HasAttrs } ;
14
14
use source_map:: { ExpnInfo , MacroBang , MacroAttribute , dummy_spanned, respan} ;
15
- use config:: { is_test_or_bench , StripUnconfigured } ;
15
+ use config:: StripUnconfigured ;
16
16
use errors:: { Applicability , FatalError } ;
17
17
use ext:: base:: * ;
18
- use ext:: build:: AstBuilder ;
19
18
use ext:: derive:: { add_derived_markers, collect_derives} ;
20
19
use ext:: hygiene:: { self , Mark , SyntaxContext } ;
21
20
use ext:: placeholders:: { placeholder, PlaceholderExpander } ;
@@ -1370,51 +1369,25 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1370
1369
self . cx . current_expansion . directory_ownership = orig_directory_ownership;
1371
1370
result
1372
1371
}
1373
- // Ensure that test functions are accessible from the test harness.
1372
+
1373
+ // Ensure that test items can be exported by the harness generator.
1374
1374
// #[test] fn foo() {}
1375
1375
// becomes:
1376
1376
// #[test] pub fn foo_gensym(){}
1377
- // #[allow(unused)]
1378
- // use foo_gensym as foo;
1379
- ast:: ItemKind :: Fn ( ..) if self . cx . ecfg . should_test => {
1380
- if self . tests_nameable && item. attrs . iter ( ) . any ( |attr| is_test_or_bench ( attr) ) {
1381
- let orig_ident = item. ident ;
1382
- let orig_vis = item. vis . clone ( ) ;
1383
-
1377
+ ast:: ItemKind :: Const ( ..)
1378
+ | ast:: ItemKind :: Static ( ..)
1379
+ | ast:: ItemKind :: Fn ( ..) if self . cx . ecfg . should_test => {
1380
+ if self . tests_nameable && attr:: contains_name ( & item. attrs , "test_case" ) {
1384
1381
// Publicize the item under gensymed name to avoid pollution
1382
+ // This means #[test_case] items can't be referenced by user code
1385
1383
item = item. map ( |mut item| {
1386
1384
item. vis = respan ( item. vis . span , ast:: VisibilityKind :: Public ) ;
1387
1385
item. ident = item. ident . gensym ( ) ;
1388
1386
item
1389
1387
} ) ;
1390
-
1391
- // Use the gensymed name under the item's original visibility
1392
- let mut use_item = self . cx . item_use_simple_ (
1393
- item. ident . span ,
1394
- orig_vis,
1395
- Some ( orig_ident) ,
1396
- self . cx . path ( item. ident . span ,
1397
- vec ! [ keywords:: SelfValue . ident( ) , item. ident] ) ) ;
1398
-
1399
- // #[allow(unused)] because the test function probably isn't being referenced
1400
- use_item = use_item. map ( |mut ui| {
1401
- ui. attrs . push (
1402
- self . cx . attribute ( DUMMY_SP , attr:: mk_list_item ( DUMMY_SP ,
1403
- Ident :: from_str ( "allow" ) , vec ! [
1404
- attr:: mk_nested_word_item( Ident :: from_str( "unused" ) )
1405
- ]
1406
- ) )
1407
- ) ;
1408
-
1409
- ui
1410
- } ) ;
1411
-
1412
- OneVector :: many (
1413
- self . fold_unnameable ( item) . into_iter ( )
1414
- . chain ( self . fold_unnameable ( use_item) ) )
1415
- } else {
1416
- self . fold_unnameable ( item)
1417
1388
}
1389
+
1390
+ self . fold_unnameable ( item)
1418
1391
}
1419
1392
_ => self . fold_unnameable ( item) ,
1420
1393
}
0 commit comments