about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorJohn Renner <john@jrenner.net>2018-08-01 11:28:08 -0700
committerJohn Renner <john@jrenner.net>2018-08-01 11:28:08 -0700
commitaf7ae2f278cb5f5b2d054d15dc36a39178a48b69 (patch)
treeeebdf8587f54f221c17811fa921065eefa506318 /src/libsyntax
parent549f0fd9f7740954cb14367d735db724669c8f79 (diff)
downloadrust-af7ae2f278cb5f5b2d054d15dc36a39178a48b69.tar.gz
rust-af7ae2f278cb5f5b2d054d15dc36a39178a48b69.zip
Allow test imports to go unused
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/expand.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 96003be3152..590d8cd6c99 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -1376,6 +1376,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
             // #[test] fn foo() {}
             // becomes:
             // #[test] pub fn foo_gensym(){}
+            // #[allow(dead_code)]
             // use foo_gensym as foo;
             ast::ItemKind::Fn(..) if self.cx.ecfg.should_test => {
                 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> {
                     });
 
                     // Use the gensymed name under the item's original visibility
-                    let use_item = self.cx.item_use_simple_(
+                    let mut use_item = self.cx.item_use_simple_(
                         item.ident.span,
                         orig_vis,
                         Some(orig_ident),
                         self.cx.path(item.ident.span,
                             vec![keywords::SelfValue.ident(), item.ident]));
 
+                    // #[allow(dead_code)] because the test function probably isn't being referenced
+                    use_item = use_item.map(|mut ui| {
+                        ui.attrs.push(
+                            self.cx.attribute(DUMMY_SP, attr::mk_list_item(DUMMY_SP,
+                                Ident::from_str("allow"), vec![
+                                    attr::mk_nested_word_item(Ident::from_str("dead_code"))
+                                ]
+                            ))
+                        );
+
+                        ui
+                    });
+
                     SmallVector::many(
                         self.fold_unnameable(item).into_iter()
                             .chain(self.fold_unnameable(use_item)))