@@ -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 } ;
@@ -37,7 +36,6 @@ use visit::{self, Visitor};
3736use rustc_data_structures:: fx:: FxHashMap ;
3837use std:: fs:: File ;
3938use std:: io:: Read ;
40- use std:: iter:: FromIterator ;
4139use std:: { iter, mem} ;
4240use std:: rc:: Rc ;
4341use std:: path:: PathBuf ;
@@ -1366,51 +1364,25 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
13661364 self . cx . current_expansion . directory_ownership = orig_directory_ownership;
13671365 result
13681366 }
1369- // Ensure that test functions are accessible from the test harness.
1367+
1368+ // Ensure that test items can be exported by the harness generator.
13701369 // #[test] fn foo() {}
13711370 // becomes:
13721371 // #[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" ) {
13801376 // Publicize the item under gensymed name to avoid pollution
1377+ // This means #[test_case] items can't be referenced by user code
13811378 item = item. map ( |mut item| {
13821379 item. vis = respan ( item. vis . span , ast:: VisibilityKind :: Public ) ;
13831380 item. ident = item. ident . gensym ( ) ;
13841381 item
13851382 } ) ;
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)
14131383 }
1384+
1385+ self . fold_unnameable ( item)
14141386 }
14151387 _ => self . fold_unnameable ( item) ,
14161388 }
0 commit comments