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 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| 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 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
