Skip to content

Commit ddbe18a

Browse files
committed
---
yaml --- r: 232723 b: refs/heads/try c: 15d6837 h: refs/heads/master i: 232721: af25505 232719: c4f4eba v: v3
1 parent 5e56b4f commit ddbe18a

File tree

5 files changed

+85
-16
lines changed

5 files changed

+85
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 45de9de1e99c3d6a38055835b0fe6c65e1ddac73
4+
refs/heads/try: 15d6837a16d727a3d37a703eaedf48e62c260290
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/libsyntax/test.rs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![allow(unused_imports)]
1515
use self::HasTestSignature::*;
1616

17+
use std::iter;
1718
use std::slice;
1819
use std::mem;
1920
use std::vec;
@@ -24,6 +25,7 @@ use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
2425
use codemap;
2526
use diagnostic;
2627
use config;
28+
use entry::{self, EntryPointType};
2729
use ext::base::ExtCtxt;
2830
use ext::build::AstBuilder;
2931
use ext::expand::ExpansionConfig;
@@ -177,22 +179,39 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
177179
// the one we're going to add. Only if compiling an executable.
178180

179181
mod_folded.items = mem::replace(&mut mod_folded.items, vec![]).move_map(|item| {
180-
item.map(|ast::Item {id, ident, attrs, node, vis, span}| {
181-
ast::Item {
182-
id: id,
183-
ident: ident,
184-
attrs: attrs.into_iter().filter_map(|attr| {
185-
if !attr.check_name("main") {
186-
Some(attr)
187-
} else {
188-
None
182+
match entry::entry_point_type(&item, self.cx.path.len() + 1) {
183+
EntryPointType::MainNamed |
184+
EntryPointType::MainAttr |
185+
EntryPointType::Start =>
186+
item.map(|ast::Item {id, ident, attrs, node, vis, span}| {
187+
let allow_str = InternedString::new("allow");
188+
let dead_code_str = InternedString::new("dead_code");
189+
let allow_dead_code_item =
190+
attr::mk_list_item(allow_str,
191+
vec![attr::mk_word_item(dead_code_str)]);
192+
let allow_dead_code = attr::mk_attr_outer(attr::mk_attr_id(),
193+
allow_dead_code_item);
194+
195+
ast::Item {
196+
id: id,
197+
ident: ident,
198+
attrs: attrs.into_iter().filter_map(|attr| {
199+
if !attr.check_name("main") {
200+
Some(attr)
201+
} else {
202+
None
203+
}
204+
})
205+
.chain(iter::once(allow_dead_code))
206+
.collect(),
207+
node: node,
208+
vis: vis,
209+
span: span
189210
}
190-
}).collect(),
191-
node: node,
192-
vis: vis,
193-
span: span
194-
}
195-
})
211+
}),
212+
EntryPointType::None |
213+
EntryPointType::OtherMain => item,
214+
}
196215
});
197216

198217
if !tests.is_empty() || !tested_submods.is_empty() {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: --test
12+
13+
#![deny(dead_code)]
14+
15+
fn dead() {} //~ error: function is never used: `dead`
16+
17+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: --test
12+
13+
#![feature(main)]
14+
15+
#![deny(dead_code)]
16+
17+
#[main]
18+
fn foo() { panic!(); }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: --test
12+
13+
#![deny(dead_code)]
14+
15+
fn main() { panic!(); }

0 commit comments

Comments
 (0)