Skip to content

Commit 14e0017

Browse files
emberianalexcrichton
authored andcommitted
---
yaml --- r: 106059 b: refs/heads/auto c: 873f740 h: refs/heads/master i: 106057: dac0b5e 106055: 8af08d1 v: v3
1 parent e79573b commit 14e0017

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: f9e0baa19a33c2b98f502d9604dabacd8f634965
16+
refs/heads/auto: 873f7408bdffdb05b23f77aa343abd05f2e3126c
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/front/test.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
9595
debug!("current path: {}",
9696
ast_util::path_name_i(self.cx.path.get().as_slice()));
9797

98-
if is_test_fn(&self.cx, i) || is_bench_fn(i) {
98+
if is_test_fn(&self.cx, i) || is_bench_fn(&self.cx, i) {
9999
match i.node {
100-
ast::ItemFn(_, purity, _, _, _)
101-
if purity == ast::UnsafeFn => {
100+
ast::ItemFn(_, ast::UnsafeFn, _, _, _) => {
102101
let sess = self.cx.sess;
103102
sess.span_fatal(i.span,
104103
"unsafe functions cannot be used for \
@@ -109,7 +108,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
109108
let test = Test {
110109
span: i.span,
111110
path: self.cx.path.get(),
112-
bench: is_bench_fn(i),
111+
bench: is_bench_fn(&self.cx, i),
113112
ignore: is_ignored(&self.cx, i),
114113
should_fail: should_fail(i)
115114
};
@@ -233,7 +232,7 @@ fn is_test_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
233232
return has_test_attr && has_test_signature(i);
234233
}
235234

236-
fn is_bench_fn(i: @ast::Item) -> bool {
235+
fn is_bench_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
237236
let has_bench_attr = attr::contains_name(i.attrs.as_slice(), "bench");
238237

239238
fn has_test_signature(i: @ast::Item) -> bool {
@@ -254,6 +253,12 @@ fn is_bench_fn(i: @ast::Item) -> bool {
254253
}
255254
}
256255

256+
if has_bench_attr && !has_test_signature(i) {
257+
let sess = cx.sess;
258+
sess.span_err(i.span, "functions used as benches must have signature \
259+
`fn(&mut BenchHarness) -> ()`");
260+
}
261+
257262
return has_bench_attr && has_test_signature(i);
258263
}
259264

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 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+
//! Test that makes sure wrongly-typed bench functions aren't ignored
14+
15+
#[bench]
16+
fn foo() { } //~ ERROR functions used as benches
17+
18+
#[bench]
19+
fn bar(x: int, y: int) { } //~ ERROR functions used as benches
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 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+
//! Test that makes sure wrongly-typed bench functions are rejected
14+
15+
// error-pattern:expected &-ptr but found int
16+
#[bench]
17+
fn bar(x: int) { }

0 commit comments

Comments
 (0)