Skip to content

Commit a9c54c6

Browse files
emberianalexcrichton
authored andcommitted
---
yaml --- r: 104921 b: refs/heads/snap-stage3 c: 873f740 h: refs/heads/master i: 104919: f63d764 v: v3
1 parent 624efdd commit a9c54c6

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: f9e0baa19a33c2b98f502d9604dabacd8f634965
4+
refs/heads/snap-stage3: 873f7408bdffdb05b23f77aa343abd05f2e3126c
55
refs/heads/try: db814977d07bd798feb24f6b74c00800ef458a13
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)