Skip to content

Commit 7312213

Browse files
committed
Rollup merge of #21504 - blackbeam:has_test_signature_fix, r=alexcrichton
Fix for `error: functions used as tests must have signature fn() -> ()` and `error: functions used as benches must have signature `fn(&mut Bencher) -> ()` in case of explicit return type declaration.
2 parents d8f46d8 + fd02920 commit 7312213

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/libsyntax/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
295295
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
296296
let no_output = match decl.output {
297297
ast::DefaultReturn(..) => true,
298+
ast::Return(ref t) if t.node == ast::TyTup(vec![]) => true,
298299
_ => false
299300
};
300301
if decl.inputs.is_empty()
@@ -331,6 +332,7 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
331332
let input_cnt = decl.inputs.len();
332333
let no_output = match decl.output {
333334
ast::DefaultReturn(..) => true,
335+
ast::Return(ref t) if t.node == ast::TyTup(vec![]) => true,
334336
_ => false
335337
};
336338
let tparm_cnt = generics.ty_params.len();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
extern crate test;
13+
14+
#[bench]
15+
fn bench_explicit_return_type(_: &mut ::test::Bencher) -> () {}
16+
17+
#[test]
18+
fn test_explicit_return_type() -> () {}
19+

0 commit comments

Comments
 (0)