-
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
Add new unconditional_recursion
lint
#11938
Add new unconditional_recursion
lint
#11938
Conversation
r? @llogiq (rustbot has picked a reviewer for you, use r? to override) |
50a4fa9
to
f3e9943
Compare
Finally fixed CI. ^^' |
I think more tests with e.g. |
f3e9943
to
e75195d
Compare
I added a lot more tests. Please tell me if you have other ideas for tests to be added. |
☔ The latest upstream changes (presumably #11878) made this pull request unmergeable. Please resolve the merge conflicts. |
e75195d
to
3da31c5
Compare
Fixed merge conflict. |
☔ The latest upstream changes (presumably #11902) made this pull request unmergeable. Please resolve the merge conflicts. |
3da31c5
to
91fd01c
Compare
Fixed merge conflict. |
How about the following test case: Impl PartialEq for Foo {
fn eq(&self, other: &Self) -> bool {
Bar(self) == Bar(other)
}
} There might also be some macro test cases that prove hairy, e.g. when the impl is supplied by proc macro. |
I disabled the lint if the code comes from macro expansion. Maybe I should just disable it from proc-macro expansion? As for your code example: not detected. But in this case, I can put recursion. I'm just not sure how "deep" we want to make it. Let's start with 3 nested levels and we'll see. |
No, leaving the example undetected is fine, loop detection would be cool but slow. And yes, detecting code inside macros would be great if we can pull off the reporting without showing weird macro-expanded code that will only confuse people. |
07b27f5
to
73f189e
Compare
73f189e
to
6b444f3
Compare
I have put back the (proc) macros checks, only excluding the ones generated from rustc. I also disabled a lint in the test to have less noise and added some comments in the code to make it easier to understand what's going on. |
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Thanks, this looks good. @bors r+ |
…g, r=llogiq Extend UNCONDITIONAL_RECURSION to check for ToString implementations Follow-up of #11938. r? `@llogiq` changelog: Extend `UNCONDITIONAL_RECURSION` to check for `ToString` implementations
Currently, rustc
unconditional_recursion
doesn't detect cases like:This is because the lint is currently implemented only for one level, and in the above code,
self == other
will then callimpl PartialEq for &T
, escaping from the detection. The fix for it seems to be a bit tricky (I started investigating potential solution to add one extra level of recursion here but completely broken at the moment).I expect that this situation will remain for a while. In the meantime, I think it's acceptable to check it directly into clippy for the time being as a lot of easy cases like this one can be easily checked (next I plan to extend it to cover other traits like
ToString
).changelog: Add new
unconditional_recursion
lint