

Add more info and suggestions to use of #[test] on invalid items by asquared3141...
source link: https://github.com/rust-lang/rust/pull/92959
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:
#[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)]
| ~~~~~~~~~~~~
Recommend
-
88
README.md Terminus 离银河中心最远的行星。 版权 建站程序版权 本站建站程序来源于 kiko-now。博客模板文件版权继承并遵循 MIT...
-
11
More info on ActionScript Optimizations in Beta Player Monday, October 21, 2002 There have a been a couple of questions about what parts of ActionScript have been optimized in the new player. I talked to the Flash Playe...
-
9
Finding more info on the CF object in ServerSide ActionScript. Friday, May 10, 2002 Joey Lott sent along an example that shows how to find some undocumented properties of the CF ob...
-
7
Want a Better PC? Try Building Your OwnAssembling a computer yourself is a good way to learn about how it works. It’s also a lost art—one due for a revival.
-
9
August 3, 2021
-
5
Conversation We currently utilize generics, primarily bound on our Rewrite trait, when formatting a RHS (e.g. on an assignment) which makes perfect sense given the high number of expres...
-
8
New issue Add more descriptive help info for needless_question_mark #8028
-
5
Android Auto's audio suggestions are appearing for more users By Will Sattelberg Published 16 hours ago Launch r...
-
13
Yogananda Muthaiah December 11, 2020 2 minut...
-
5
Conversation Contributor...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK