@@ -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 } ;
@@ -37,7 +36,6 @@ use visit::{self, Visitor};
37
36
use rustc_data_structures:: fx:: FxHashMap ;
38
37
use std:: fs:: File ;
39
38
use std:: io:: Read ;
40
- use std:: iter:: FromIterator ;
41
39
use std:: { iter, mem} ;
42
40
use std:: rc:: Rc ;
43
41
use std:: path:: PathBuf ;
@@ -1366,51 +1364,25 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1366
1364
self . cx . current_expansion . directory_ownership = orig_directory_ownership;
1367
1365
result
1368
1366
}
1369
- // Ensure that test functions are accessible from the test harness.
1367
+
1368
+ // Ensure that test items can be exported by the harness generator.
1370
1369
// #[test] fn foo() {}
1371
1370
// becomes:
1372
1371
// #[test] pub fn foo_gensym(){}
1373
- // #[allow(unused)]
1374
- // use foo_gensym as foo;
1375
- ast:: ItemKind :: Fn ( ..) if self . cx . ecfg . should_test => {
1376
- if self . tests_nameable && item. attrs . iter ( ) . any ( |attr| is_test_or_bench ( attr) ) {
1377
- let orig_ident = item. ident ;
1378
- let orig_vis = item. vis . clone ( ) ;
1379
-
1372
+ ast:: ItemKind :: Const ( ..)
1373
+ | ast:: ItemKind :: Static ( ..)
1374
+ | ast:: ItemKind :: Fn ( ..) if self . cx . ecfg . should_test => {
1375
+ if self . tests_nameable && attr:: contains_name ( & item. attrs , "test_case" ) {
1380
1376
// Publicize the item under gensymed name to avoid pollution
1377
+ // This means #[test_case] items can't be referenced by user code
1381
1378
item = item. map ( |mut item| {
1382
1379
item. vis = respan ( item. vis . span , ast:: VisibilityKind :: Public ) ;
1383
1380
item. ident = item. ident . gensym ( ) ;
1384
1381
item
1385
1382
} ) ;
1386
-
1387
- // Use the gensymed name under the item's original visibility
1388
- let mut use_item = self . cx . item_use_simple_ (
1389
- item. ident . span ,
1390
- orig_vis,
1391
- Some ( orig_ident) ,
1392
- self . cx . path ( item. ident . span ,
1393
- vec ! [ keywords:: SelfValue . ident( ) , item. ident] ) ) ;
1394
-
1395
- // #[allow(unused)] because the test function probably isn't being referenced
1396
- use_item = use_item. map ( |mut ui| {
1397
- ui. attrs . push (
1398
- self . cx . attribute ( DUMMY_SP , attr:: mk_list_item ( DUMMY_SP ,
1399
- Ident :: from_str ( "allow" ) , vec ! [
1400
- attr:: mk_nested_word_item( Ident :: from_str( "unused" ) )
1401
- ]
1402
- ) )
1403
- ) ;
1404
-
1405
- ui
1406
- } ) ;
1407
-
1408
- OneVector :: from_iter (
1409
- self . fold_unnameable ( item) . into_iter ( )
1410
- . chain ( self . fold_unnameable ( use_item) ) )
1411
- } else {
1412
- self . fold_unnameable ( item)
1413
1383
}
1384
+
1385
+ self . fold_unnameable ( item)
1414
1386
}
1415
1387
_ => self . fold_unnameable ( item) ,
1416
1388
}
0 commit comments