mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-18 18:47:29 +00:00
parent
45de9de1e9
commit
15d6837a16
@ -14,6 +14,7 @@
|
|||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
use self::HasTestSignature::*;
|
use self::HasTestSignature::*;
|
||||||
|
|
||||||
|
use std::iter;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
@ -24,6 +25,7 @@ use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
|
|||||||
use codemap;
|
use codemap;
|
||||||
use diagnostic;
|
use diagnostic;
|
||||||
use config;
|
use config;
|
||||||
|
use entry::{self, EntryPointType};
|
||||||
use ext::base::ExtCtxt;
|
use ext::base::ExtCtxt;
|
||||||
use ext::build::AstBuilder;
|
use ext::build::AstBuilder;
|
||||||
use ext::expand::ExpansionConfig;
|
use ext::expand::ExpansionConfig;
|
||||||
@ -177,7 +179,19 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
|
|||||||
// the one we're going to add. Only if compiling an executable.
|
// 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| {
|
mod_folded.items = mem::replace(&mut mod_folded.items, vec![]).move_map(|item| {
|
||||||
|
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}| {
|
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 {
|
ast::Item {
|
||||||
id: id,
|
id: id,
|
||||||
ident: ident,
|
ident: ident,
|
||||||
@ -187,12 +201,17 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}).collect(),
|
})
|
||||||
|
.chain(iter::once(allow_dead_code))
|
||||||
|
.collect(),
|
||||||
node: node,
|
node: node,
|
||||||
vis: vis,
|
vis: vis,
|
||||||
span: span
|
span: span
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
|
EntryPointType::None |
|
||||||
|
EntryPointType::OtherMain => item,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if !tests.is_empty() || !tested_submods.is_empty() {
|
if !tests.is_empty() || !tested_submods.is_empty() {
|
||||||
|
17
src/test/compile-fail/test-warns-dead-code.rs
Normal file
17
src/test/compile-fail/test-warns-dead-code.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// compile-flags: --test
|
||||||
|
|
||||||
|
#![deny(dead_code)]
|
||||||
|
|
||||||
|
fn dead() {} //~ error: function is never used: `dead`
|
||||||
|
|
||||||
|
fn main() {}
|
18
src/test/run-pass/test-main-not-dead-attr.rs
Normal file
18
src/test/run-pass/test-main-not-dead-attr.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// compile-flags: --test
|
||||||
|
|
||||||
|
#![feature(main)]
|
||||||
|
|
||||||
|
#![deny(dead_code)]
|
||||||
|
|
||||||
|
#[main]
|
||||||
|
fn foo() { panic!(); }
|
15
src/test/run-pass/test-main-not-dead.rs
Normal file
15
src/test/run-pass/test-main-not-dead.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// compile-flags: --test
|
||||||
|
|
||||||
|
#![deny(dead_code)]
|
||||||
|
|
||||||
|
fn main() { panic!(); }
|
Loading…
Reference in New Issue
Block a user