-
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
new lint: redundant_locals
#10885
new lint: redundant_locals
#10885
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Jarcho (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Okay, so I'm really confused on how the the |
This is likely because |
@rustbot review |
@max-niederman thanks for the PR! We follow a no merge-commit policy. Can you help to resolve the conflict by rebasing this to @Centri3 Do you want to help review this PR since you've looked at it? |
I was actually just doing that :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good so far, but it misses some redundant locals.
Please add a test case with a type-ascribed local (e.g. |
Similarly some test cases for We might need to add a let guard = mutex.lock().unwrap();
// ..
{
let guard = guard;
// ..
}
// mutex is now unlocked |
@Centri3 @Alexendoo I intentionally wrote the lint to only check redefinitions in the same block in order to prevent changes to the drop order, but I definitely think it would be better to check all redefinitions and use |
I'll also disable linting on type-ascribed locals. Totally forgot about coercion 🤦. |
a057cdf
to
c3d756f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, I've left some comments on what can be improved.
☔ The latest upstream changes (presumably #10921) made this pull request unmergeable. Please resolve the merge conflicts. |
188f153
to
3ad1fbb
Compare
I finally got around to working on this again and I'm pretty sure it's in a good state. It would be good to check for multiple-binding local statements, but that's way harder and definitely suffers from diminishing returns in terms of applicability. |
☔ The latest upstream changes (presumably #10951) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thanks! I may do the (x, y)
idea as a followup if that's fine with you ^^
@dswij, can you take a look as well?
3ad1fbb
to
9076d88
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is about ready to be merged :D Just two minor nits, thanks!
☔ The latest upstream changes (presumably #10884) made this pull request unmergeable. Please resolve the merge conflicts. |
c1cfb3a
to
88d94d4
Compare
☔ The latest upstream changes (presumably #11140) made this pull request unmergeable. Please resolve the merge conflicts. |
Once you rebase and add the crate type this is ready :) |
88d94d4
to
d913cf9
Compare
Sorry, also please squash. |
fix dogfood lints in `redundant_local` keep `redundant_local` from running in proc macros rewrite `redundant_local` as late pass make redundant_local's `find_binding` more readable pluralize `redundant_locals` name add test for `redundant_locals` in macros test `redundant_locals` in proc macros use more destructuring in `redundant_locals` fix: format redundant_locals.rs ignore needless_pass_by_mut_ref in redundant_locals test
d913cf9
to
008ba2b
Compare
Thanks! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This lint checks for code like the following:
It checks (afaik) all cases where a binding is shadowed by its own value in the same block, including function parameters. This has no effect and is almost certainly accidental, so it's in the
correctness
category likeself_assignment
.This also lays the groundwork for a more generalized version of #5102.
changelog: new lint: [
redundant_local
]