diff options
| author | William Throwe <wtt6@cornell.edu> | 2015-08-23 21:46:10 -0400 |
|---|---|---|
| committer | William Throwe <wtt6@cornell.edu> | 2015-08-24 20:28:24 -0400 |
| commit | 15d6837a16d727a3d37a703eaedf48e62c260290 (patch) | |
| tree | 0d8f217c8b1d17bdbc178e95647aae7a97f7d369 /src/libsyntax | |
| parent | 45de9de1e99c3d6a38055835b0fe6c65e1ddac73 (diff) | |
| download | rust-15d6837a16d727a3d37a703eaedf48e62c260290.tar.gz rust-15d6837a16d727a3d37a703eaedf48e62c260290.zip | |
Mark main-like functions allow(dead_code) in tests
Fixes #12327.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/test.rs | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 26fb287ce35..3fbcbd728aa 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -14,6 +14,7 @@ #![allow(unused_imports)] use self::HasTestSignature::*; +use std::iter; use std::slice; use std::mem; use std::vec; @@ -24,6 +25,7 @@ use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute}; use codemap; use diagnostic; use config; +use entry::{self, EntryPointType}; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::expand::ExpansionConfig; @@ -177,22 +179,39 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { // the one we're going to add. Only if compiling an executable. mod_folded.items = mem::replace(&mut mod_folded.items, vec![]).move_map(|item| { - item.map(|ast::Item {id, ident, attrs, node, vis, span}| { - ast::Item { - id: id, - ident: ident, - attrs: attrs.into_iter().filter_map(|attr| { - if !attr.check_name("main") { - Some(attr) - } else { - None + match entry::entry_point_type(&item, self.cx.path.len() + 1) { + EntryPointType::MainNamed | + EntryPointType::MainAttr | + EntryPointType::Start => + item.map(|ast::Item {id, ident, attrs, node, vis, span}| { + let allow_str = InternedString::new("allow"); + let dead_code_str = InternedString::new("dead_code"); + let allow_dead_code_item = + attr::mk_list_item(allow_str, + vec![attr::mk_word_item(dead_code_str)]); + let allow_dead_code = attr::mk_attr_outer(attr::mk_attr_id(), + allow_dead_code_item); + + ast::Item { + id: id, + ident: ident, + attrs: attrs.into_iter().filter_map(|attr| { + if !attr.check_name("main") { + Some(attr) + } else { + None + } + }) + .chain(iter::once(allow_dead_code)) + .collect(), + node: node, + vis: vis, + span: span } - }).collect(), - node: node, - vis: vis, - span: span - } - }) + }), + EntryPointType::None | + EntryPointType::OtherMain => item, + } }); if !tests.is_empty() || !tested_submods.is_empty() { |
