diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-18 16:23:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-18 16:23:29 +0100 |
| commit | 659382fa47e9a7c29451ed407c4062f86dee07b1 (patch) | |
| tree | 8dbdd1fc0ffb5d05c32df766dcc41b22ea2801fc /src/test/ui/issues | |
| parent | e3ded4fc4fa15f0b7acee429edf30e1e0cde26f8 (diff) | |
| parent | 6d05e2a9afb558e4e9668e54db6747e4d8a8383a (diff) | |
| download | rust-659382fa47e9a7c29451ed407c4062f86dee07b1.tar.gz rust-659382fa47e9a7c29451ed407c4062f86dee07b1.zip | |
Rollup merge of #92959 - asquared31415:test-non-fn-help, r=estebank
Add more info and suggestions to use of #[test] on invalid items
This pr changes the diagnostics for using `#[test]` on an item that can't be used as a test to explain that the attribute has no meaningful effect on non-functions and suggests the use of `#[cfg(test)]` for conditional compilation instead.
Example change:
```rs
#[test]
mod test {}
```
previously output
```
error: only functions may be used as tests
--> src/lib.rs:2:1
|
2 | mod test {}
| ^^^^^^^^^^^
```
now outputs
```
error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:3:1
|
LL | #[test]
| ^^^^^^^
LL | mod test {}
| ----------- expected a non-associated function, found a module
|
= note: the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
help: replace with conditional compilation to make the item only exist when tests are being run
|
LL | #[cfg(test)]
| ~~~~~~~~~~~~
```
Diffstat (limited to 'src/test/ui/issues')
| -rw-r--r-- | src/test/ui/issues/issue-14772.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-14772.stderr | 8 |
2 files changed, 0 insertions, 14 deletions
diff --git a/src/test/ui/issues/issue-14772.rs b/src/test/ui/issues/issue-14772.rs deleted file mode 100644 index 8f6745246fd..00000000000 --- a/src/test/ui/issues/issue-14772.rs +++ /dev/null @@ -1,6 +0,0 @@ -// compile-flags: --test - -#[test] -mod foo {} //~ ERROR only functions may be used as tests - -fn main() {} diff --git a/src/test/ui/issues/issue-14772.stderr b/src/test/ui/issues/issue-14772.stderr deleted file mode 100644 index 253fec5e578..00000000000 --- a/src/test/ui/issues/issue-14772.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: only functions may be used as tests - --> $DIR/issue-14772.rs:4:1 - | -LL | mod foo {} - | ^^^^^^^^^^ - -error: aborting due to previous error - |
