-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lint on should_panic tests without reasons #10956
Comments
Thank you! Love this. |
imho this should be enabled by default. I think something worth noting here is that This to me brings up a different issue that isn't really to do with Clippy at all: should there also be a strict equals version of |
FWIW I chose to make it pedantic in the PR because it does seem rather strict and looks like it would warn a loooot of code (a quick github code search showed 30k instances of |
I haven't checked yet but my hunch is |
I did a little bit of digging and it seems this has existed for quite some time, it was added in rust-lang/rust#19560 (back then it was called
I agree, I feel like this is not very well known. I guess that if this was |
Oh wow! I would have guessed more recent than that haha.
Love this thinking |
A lot of people will simply be unamused by 1000 tests flickering a warning as they try to maintain a "clippy clean" codebase. However, I think that there's reasonable justification of "the test is sufficiently risking incorrectness otherwise", and I guess I have a more relaxed relationship with clippy personally. I think this kind of lint is way more useful since it's about "real" correctness on some level instead of mere stylistic concerns, which is why I suggested it. |
What it does
For a
#[test]
that has#[should_panic]
, this lint would fire unless given a reason, e.g.#[should_panic = "No such file or directory"]
.Advantage
This prevents a should-panic test from accepting another reason when it fires, and there are many reasons such a test could panic.
Drawbacks
It could fire on tests that are genuinely expecting many possible panic reasons and don't care which one fires. These are probably very few in practice, but it could justify making it a "pedantic" lint.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: