@@ -450,14 +450,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
450
450
let ( fragment_with_placeholders, invocations) = {
451
451
let mut collector = InvocationCollector {
452
452
cfg : StripUnconfigured {
453
- should_test : self . cx . ecfg . should_test ,
454
453
sess : self . cx . parse_sess ,
455
454
features : self . cx . ecfg . features ,
456
455
} ,
457
456
cx : self . cx ,
458
457
invocations : Vec :: new ( ) ,
459
458
monotonic : self . monotonic ,
460
- tests_nameable : true ,
461
459
} ;
462
460
( fragment. fold_with ( & mut collector) , collector. invocations )
463
461
} ;
@@ -475,7 +473,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
475
473
476
474
fn fully_configure ( & mut self , item : Annotatable ) -> Annotatable {
477
475
let mut cfg = StripUnconfigured {
478
- should_test : self . cx . ecfg . should_test ,
479
476
sess : self . cx . parse_sess ,
480
477
features : self . cx . ecfg . features ,
481
478
} ;
@@ -1047,11 +1044,6 @@ struct InvocationCollector<'a, 'b: 'a> {
1047
1044
cfg : StripUnconfigured < ' a > ,
1048
1045
invocations : Vec < Invocation > ,
1049
1046
monotonic : bool ,
1050
-
1051
- /// Test functions need to be nameable. Tests inside functions or in other
1052
- /// unnameable locations need to be ignored. `tests_nameable` tracks whether
1053
- /// any test functions found in the current context would be nameable.
1054
- tests_nameable : bool ,
1055
1047
}
1056
1048
1057
1049
impl < ' a , ' b > InvocationCollector < ' a , ' b > {
@@ -1069,20 +1061,6 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
1069
1061
placeholder ( fragment_kind, NodeId :: placeholder_from_mark ( mark) )
1070
1062
}
1071
1063
1072
- /// Folds the item allowing tests to be expanded because they are still nameable.
1073
- /// This should probably only be called with module items
1074
- fn fold_nameable ( & mut self , item : P < ast:: Item > ) -> OneVector < P < ast:: Item > > {
1075
- fold:: noop_fold_item ( item, self )
1076
- }
1077
-
1078
- /// Folds the item but doesn't allow tests to occur within it
1079
- fn fold_unnameable ( & mut self , item : P < ast:: Item > ) -> OneVector < P < ast:: Item > > {
1080
- let was_nameable = mem:: replace ( & mut self . tests_nameable , false ) ;
1081
- let items = fold:: noop_fold_item ( item, self ) ;
1082
- self . tests_nameable = was_nameable;
1083
- items
1084
- }
1085
-
1086
1064
fn collect_bang ( & mut self , mac : ast:: Mac , span : Span , kind : AstFragmentKind ) -> AstFragment {
1087
1065
self . collect ( kind, InvocationKind :: Bang { mac : mac, ident : None , span : span } )
1088
1066
}
@@ -1297,7 +1275,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1297
1275
fn fold_item ( & mut self , item : P < ast:: Item > ) -> OneVector < P < ast:: Item > > {
1298
1276
let item = configure ! ( self , item) ;
1299
1277
1300
- let ( attr, traits, mut item) = self . classify_item ( item) ;
1278
+ let ( attr, traits, item) = self . classify_item ( item) ;
1301
1279
if attr. is_some ( ) || !traits. is_empty ( ) {
1302
1280
let item = Annotatable :: Item ( item) ;
1303
1281
return self . collect_attr ( attr, traits, item, AstFragmentKind :: Items ) . make_items ( ) ;
@@ -1319,7 +1297,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1319
1297
}
1320
1298
ast:: ItemKind :: Mod ( ast:: Mod { inner, .. } ) => {
1321
1299
if item. ident == keywords:: Invalid . ident ( ) {
1322
- return self . fold_nameable ( item) ;
1300
+ return noop_fold_item ( item, self ) ;
1323
1301
}
1324
1302
1325
1303
let orig_directory_ownership = self . cx . current_expansion . directory_ownership ;
@@ -1359,32 +1337,13 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1359
1337
1360
1338
let orig_module =
1361
1339
mem:: replace ( & mut self . cx . current_expansion . module , Rc :: new ( module) ) ;
1362
- let result = self . fold_nameable ( item) ;
1340
+ let result = noop_fold_item ( item, self ) ;
1363
1341
self . cx . current_expansion . module = orig_module;
1364
1342
self . cx . current_expansion . directory_ownership = orig_directory_ownership;
1365
1343
result
1366
1344
}
1367
1345
1368
- // Ensure that test items can be exported by the harness generator.
1369
- // #[test] fn foo() {}
1370
- // becomes:
1371
- // #[test] pub fn foo_gensym(){}
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" ) {
1376
- // Publicize the item under gensymed name to avoid pollution
1377
- // This means #[test_case] items can't be referenced by user code
1378
- item = item. map ( |mut item| {
1379
- item. vis = respan ( item. vis . span , ast:: VisibilityKind :: Public ) ;
1380
- item. ident = item. ident . gensym ( ) ;
1381
- item
1382
- } ) ;
1383
- }
1384
-
1385
- self . fold_unnameable ( item)
1386
- }
1387
- _ => self . fold_unnameable ( item) ,
1346
+ _ => noop_fold_item ( item, self ) ,
1388
1347
}
1389
1348
}
1390
1349
@@ -1609,6 +1568,7 @@ impl<'feat> ExpansionConfig<'feat> {
1609
1568
feature_tests ! {
1610
1569
fn enable_quotes = quote,
1611
1570
fn enable_asm = asm,
1571
+ fn enable_custom_test_frameworks = custom_test_frameworks,
1612
1572
fn enable_global_asm = global_asm,
1613
1573
fn enable_log_syntax = log_syntax,
1614
1574
fn enable_concat_idents = concat_idents,
0 commit comments