tests/ui/test-attrs: add annotations for reference rules

This commit is contained in:
Daniel Scherzer 2026-02-11 18:46:14 -08:00
parent 7057231bd7
commit 6e65aba9a3
No known key found for this signature in database
GPG key ID: EC64F10448CEAB6F
15 changed files with 38 additions and 30 deletions

View file

@ -1,4 +1,5 @@
//@ compile-flags: --test
//@ reference: attributes.testing.test.allowed-positions
fn align_offset_weird_strides() {
#[test]

View file

@ -1,5 +1,5 @@
error: the `#[test]` attribute may only be used on a free function
--> $DIR/issue-109816.rs:4:5
--> $DIR/issue-109816.rs:5:5
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions

View file

@ -1,4 +1,5 @@
//@ compile-flags:--test
//@ reference: attributes.testing.test.allowed-positions
struct A {}

View file

@ -1,5 +1,5 @@
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-attr-non-associated-functions.rs:6:5
--> $DIR/test-attr-non-associated-functions.rs:7:5
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -11,7 +11,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-attr-non-associated-functions.rs:11:5
--> $DIR/test-attr-non-associated-functions.rs:12:5
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions

View file

@ -1,4 +1,5 @@
//@ compile-flags: --test
//@ reference: attributes.testing.test.allowed-positions
#[test]
fn foo() -> Result<(), ()> {

View file

@ -1,29 +1,29 @@
error: functions used as tests can not have any arguments
--> $DIR/test-function-signature.rs:14:1
--> $DIR/test-function-signature.rs:15:1
|
LL | fn baz(val: i32) {}
| ^^^^^^^^^^^^^^^^^^^
error: functions used as tests can not have any non-lifetime generic parameters
--> $DIR/test-function-signature.rs:22:1
--> $DIR/test-function-signature.rs:23:1
|
LL | fn type_generic<T>() {}
| ^^^^^^^^^^^^^^^^^^^^^^^
error: functions used as tests can not have any non-lifetime generic parameters
--> $DIR/test-function-signature.rs:25:1
--> $DIR/test-function-signature.rs:26:1
|
LL | fn const_generic<const N: usize>() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: functions used as tests can not have any arguments
--> $DIR/test-function-signature.rs:30:5
--> $DIR/test-function-signature.rs:31:5
|
LL | fn foo(arg: ()) {}
| ^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `i32: Termination` is not satisfied
--> $DIR/test-function-signature.rs:9:13
--> $DIR/test-function-signature.rs:10:13
|
LL | #[test]
| ------- in this attribute macro expansion

View file

@ -1,4 +1,5 @@
//@ compile-flags: --test
//@ reference: attributes.testing.test.allowed-positions
#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function
mod test {}

View file

@ -1,5 +1,5 @@
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:3:1
--> $DIR/test-on-not-fn.rs:4:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -13,7 +13,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:6:1
--> $DIR/test-on-not-fn.rs:7:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -33,7 +33,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:20:1
--> $DIR/test-on-not-fn.rs:21:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -47,7 +47,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:23:1
--> $DIR/test-on-not-fn.rs:24:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -61,7 +61,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:26:1
--> $DIR/test-on-not-fn.rs:27:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -75,7 +75,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:29:1
--> $DIR/test-on-not-fn.rs:30:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -89,7 +89,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:32:1
--> $DIR/test-on-not-fn.rs:33:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -103,7 +103,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:35:1
--> $DIR/test-on-not-fn.rs:36:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -119,7 +119,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:40:1
--> $DIR/test-on-not-fn.rs:41:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -133,7 +133,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:43:1
--> $DIR/test-on-not-fn.rs:44:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -150,7 +150,7 @@ LL + #[cfg(test)]
|
error: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:50:1
--> $DIR/test-on-not-fn.rs:51:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
@ -168,7 +168,7 @@ LL + #[cfg(test)]
|
warning: the `#[test]` attribute may only be used on a free function
--> $DIR/test-on-not-fn.rs:61:1
--> $DIR/test-on-not-fn.rs:62:1
|
LL | #[test]
| ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions

View file

@ -4,6 +4,7 @@
//@ run-pass
//@ check-run-results
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ reference: attributes.testing.test.success
// Tests the output of the test harness with only passed tests.

View file

@ -1,4 +1,5 @@
//@ compile-flags: --test
//@ reference: attributes.testing.should_panic.syntax
#[test]
#[should_panic = "foo"]

View file

@ -1,5 +1,5 @@
error[E0539]: malformed `should_panic` attribute input
--> $DIR/test-should-panic-attr.rs:10:1
--> $DIR/test-should-panic-attr.rs:11:1
|
LL | #[should_panic(expected)]
| ^^^^^^^^^^^^^^^--------^^
@ -19,7 +19,7 @@ LL + #[should_panic]
|
error[E0539]: malformed `should_panic` attribute input
--> $DIR/test-should-panic-attr.rs:19:1
--> $DIR/test-should-panic-attr.rs:20:1
|
LL | #[should_panic(expect)]
| ^^^^^^^^^^^^^^--------^
@ -39,7 +39,7 @@ LL + #[should_panic]
|
error[E0539]: malformed `should_panic` attribute input
--> $DIR/test-should-panic-attr.rs:28:1
--> $DIR/test-should-panic-attr.rs:29:1
|
LL | #[should_panic(expected(foo, bar))]
| ^^^^^^^^^^^^^^^------------------^^
@ -60,7 +60,7 @@ LL + #[should_panic]
|
error[E0805]: malformed `should_panic` attribute input
--> $DIR/test-should-panic-attr.rs:37:1
--> $DIR/test-should-panic-attr.rs:38:1
|
LL | #[should_panic(expected = "foo", bar)]
| ^^^^^^^^^^^^^^-----------------------^

View file

@ -8,6 +8,7 @@
//@ normalize-stdout: "TypeId\(0x[0-9a-f]+\)" -> "TypeId($$HEX)"
//@ needs-threads
//@ needs-unwind (panic)
//@ reference: attributes.testing.should_panic.expected
#[test]
#[should_panic]

View file

@ -1,13 +1,13 @@
thread 'should_panic_with_any_message' ($TID) panicked at $DIR/test-should-panic-failed-show-span.rs:15:5:
thread 'should_panic_with_any_message' ($TID) panicked at $DIR/test-should-panic-failed-show-span.rs:16:5:
Panic!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'should_panic_with_message' ($TID) panicked at $DIR/test-should-panic-failed-show-span.rs:21:5:
thread 'should_panic_with_message' ($TID) panicked at $DIR/test-should-panic-failed-show-span.rs:22:5:
message
thread 'should_panic_with_substring_panics_with_incorrect_string' ($TID) panicked at $DIR/test-should-panic-failed-show-span.rs:39:5:
thread 'should_panic_with_substring_panics_with_incorrect_string' ($TID) panicked at $DIR/test-should-panic-failed-show-span.rs:40:5:
ZOMGWTFBBQ
thread 'should_panic_with_substring_panics_with_non_string_value' ($TID) panicked at $DIR/test-should-panic-failed-show-span.rs:46:5:
thread 'should_panic_with_substring_panics_with_non_string_value' ($TID) panicked at $DIR/test-should-panic-failed-show-span.rs:47:5:
Box<dyn Any>

View file

@ -10,9 +10,9 @@ test should_panic_with_substring_panics_with_non_string_value - should panic ...
failures:
---- should_panic_with_any_message_does_not_panic stdout ----
note: test did not panic as expected at $DIR/test-should-panic-failed-show-span.rs:26:4
note: test did not panic as expected at $DIR/test-should-panic-failed-show-span.rs:27:4
---- should_panic_with_message_does_not_panic stdout ----
note: test did not panic as expected at $DIR/test-should-panic-failed-show-span.rs:32:4
note: test did not panic as expected at $DIR/test-should-panic-failed-show-span.rs:33:4
---- should_panic_with_substring_panics_with_incorrect_string stdout ----
note: panic did not contain expected string
panic message: "ZOMGWTFBBQ"

View file

@ -1,5 +1,6 @@
//@ run-pass
//@ compile-flags: --cfg test
//@ reference: cfg.test
// Make sure `--cfg test` does not inject test harness