@@ -12,10 +12,9 @@ use ast::{self, Block, Ident, NodeId, PatKind, Path};
1212use ast:: { MacStmtStyle , StmtKind , ItemKind } ;
1313use attr:: { self , HasAttrs } ;
1414use source_map:: { ExpnInfo , MacroBang , MacroAttribute , dummy_spanned, respan} ;
15- use config:: { is_test_or_bench , StripUnconfigured } ;
15+ use config:: StripUnconfigured ;
1616use errors:: { Applicability , FatalError } ;
1717use ext:: base:: * ;
18- use ext:: build:: AstBuilder ;
1918use ext:: derive:: { add_derived_markers, collect_derives} ;
2019use ext:: hygiene:: { self , Mark , SyntaxContext } ;
2120use ext:: placeholders:: { placeholder, PlaceholderExpander } ;
@@ -1370,51 +1369,25 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
13701369 self . cx . current_expansion . directory_ownership = orig_directory_ownership;
13711370 result
13721371 }
1373- // Ensure that test functions are accessible from the test harness.
1372+
1373+ // Ensure that test items can be exported by the harness generator.
13741374 // #[test] fn foo() {}
13751375 // becomes:
13761376 // #[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" ) {
13841381 // Publicize the item under gensymed name to avoid pollution
1382+ // This means #[test_case] items can't be referenced by user code
13851383 item = item. map ( |mut item| {
13861384 item. vis = respan ( item. vis . span , ast:: VisibilityKind :: Public ) ;
13871385 item. ident = item. ident . gensym ( ) ;
13881386 item
13891387 } ) ;
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)
14171388 }
1389+
1390+ self . fold_unnameable ( item)
14181391 }
14191392 _ => self . fold_unnameable ( item) ,
14201393 }
0 commit comments