Skip to content

Commit 5049743

Browse files
author
Lukas Markeffsky
committed
Add test for test function signature verification.
1 parent 774f782 commit 5049743

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// compile-flags: --test
2+
3+
#[test]
4+
fn foo() -> Result<(), ()> {
5+
Ok(())
6+
}
7+
8+
#[test]
9+
fn bar() -> i32 { //~ ERROR the trait bound `i32: Termination` is not satisfied
10+
0
11+
}
12+
13+
#[test]
14+
fn baz(val: i32) {} //~ ERROR functions used as tests can not have any arguments
15+
16+
#[test]
17+
fn lifetime_generic<'a>() -> Result<(), &'a str> {
18+
Err("coerce me to any lifetime")
19+
}
20+
21+
#[test]
22+
fn type_generic<T>() {} //~ ERROR functions used as tests can not have any non-lifetime generic parameters
23+
24+
#[test]
25+
fn const_generic<const N: usize>() {} //~ ERROR functions used as tests can not have any non-lifetime generic parameters
26+
27+
// Regression test for <https://github.com/rust-lang/rust/issues/112360>. This used to ICE.
28+
fn nested() {
29+
#[test]
30+
fn foo(arg: ()) {} //~ ERROR functions used as tests can not have any arguments
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error: functions used as tests can not have any arguments
2+
--> $DIR/test-function-signature.rs:14:1
3+
|
4+
LL | fn baz(val: i32) {}
5+
| ^^^^^^^^^^^^^^^^^^^
6+
7+
error: functions used as tests can not have any non-lifetime generic parameters
8+
--> $DIR/test-function-signature.rs:22:1
9+
|
10+
LL | fn type_generic<T>() {}
11+
| ^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: functions used as tests can not have any non-lifetime generic parameters
14+
--> $DIR/test-function-signature.rs:25:1
15+
|
16+
LL | fn const_generic<const N: usize>() {}
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error: functions used as tests can not have any arguments
20+
--> $DIR/test-function-signature.rs:30:5
21+
|
22+
LL | fn foo(arg: ()) {}
23+
| ^^^^^^^^^^^^^^^^^^
24+
25+
error[E0277]: the trait bound `i32: Termination` is not satisfied
26+
--> $DIR/test-function-signature.rs:9:13
27+
|
28+
LL | #[test]
29+
| ------- in this procedural macro expansion
30+
LL | fn bar() -> i32 {
31+
| ^^^ the trait `Termination` is not implemented for `i32`
32+
|
33+
note: required by a bound in `assert_test_result`
34+
--> $SRC_DIR/test/src/lib.rs:LL:COL
35+
= note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
36+
37+
error: aborting due to 5 previous errors
38+
39+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)