Skip to content

Commit 690be10

Browse files
committed
---
yaml --- r: 233722 b: refs/heads/beta c: 15d6837 h: refs/heads/master v: v3
1 parent a397b9f commit 690be10

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
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 45de9de1e99c3d6a38055835b0fe6c65e1ddac73
26+
refs/heads/beta: 15d6837a16d727a3d37a703eaedf48e62c260290
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 370fe2786109360f7c35b8ba552b83b773dd71d6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/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)