Skip to content

Commit af7ae2f

Browse files
committed
Allow test imports to go unused
1 parent 549f0fd commit af7ae2f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libsyntax/ext/expand.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
13761376
// #[test] fn foo() {}
13771377
// becomes:
13781378
// #[test] pub fn foo_gensym(){}
1379+
// #[allow(dead_code)]
13791380
// use foo_gensym as foo;
13801381
ast::ItemKind::Fn(..) if self.cx.ecfg.should_test => {
13811382
if self.tests_nameable && item.attrs.iter().any(|attr| is_test_or_bench(attr)) {
@@ -1390,13 +1391,26 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
13901391
});
13911392

13921393
// Use the gensymed name under the item's original visibility
1393-
let use_item = self.cx.item_use_simple_(
1394+
let mut use_item = self.cx.item_use_simple_(
13941395
item.ident.span,
13951396
orig_vis,
13961397
Some(orig_ident),
13971398
self.cx.path(item.ident.span,
13981399
vec![keywords::SelfValue.ident(), item.ident]));
13991400

1401+
// #[allow(dead_code)] because the test function probably isn't being referenced
1402+
use_item = use_item.map(|mut ui| {
1403+
ui.attrs.push(
1404+
self.cx.attribute(DUMMY_SP, attr::mk_list_item(DUMMY_SP,
1405+
Ident::from_str("allow"), vec![
1406+
attr::mk_nested_word_item(Ident::from_str("dead_code"))
1407+
]
1408+
))
1409+
);
1410+
1411+
ui
1412+
});
1413+
14001414
SmallVector::many(
14011415
self.fold_unnameable(item).into_iter()
14021416
.chain(self.fold_unnameable(use_item)))

0 commit comments

Comments
 (0)