-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add rebind_fn_arg_as_mut
lint
#6245
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
Conversation
r? @Manishearth (rust_highfive has picked a reviewer for you, use r? to override) |
I just re-read the discussion in #1657 and noticed I still have to make it bail out when inside macros, right? @Manishearth just as in my other PR, can you add the hacktoberfest-accepted label to this one before monday? |
9d8b33a
to
ad9c1cc
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.
Approving for hacktoberfest, but the approach is incorrect.
This should not need a visitor IMO, the way to structure the code should be to look for let mut x = x;
statements, and then check if the pattern x
was defined in a fn arg by checking the source of its def id.
And yes, you'll need to introduce a macro check, see how |
ad9c1cc
to
ecf5c5b
Compare
Alright, cool! I ended up learning some new things. Thanks for the feedback. Could you explain the difference between |
|
ecf5c5b
to
c292da8
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.
impl seems great, but i want a second opinion on the lint level. Unsure if it should be style or pedantic.
/// } | ||
/// ``` | ||
pub REBIND_FN_ARG_AS_MUT, | ||
style, |
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.
@ebroto what do you think of the lint level for this?
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 should be a style
lint, but IMO we should:
- Check that the scope of the linted binding is the same as the scope of the parameter (so, the whole function body)
- Fix the known problem
If we want to leave these cases for a follow-up, I would add the lint to nursery
for the time being.
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 I can address your first suggestion this weekend.
As to the second, if by fixing you mean generating an applicable suggestion, I only didn't do it because the output looked awful: a suggestion to remove an entire line just prints out a blank that might confuse the user if they don't pay attention to the line number. If it's possible to make it better than that, let me know!
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.
Sorry for not being precise. I meant to avoid the false positive when the parameter has been shadowed.
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.
Oh, right. But actually, I think that is fixed by my new impl. I'm comparing the resolution id for the variable (path) with the HIR id of the parameter's pattern. The thing is, I'm starting to think we should expand this lint to cover not only function parameters but any binding. Is there some case in which let mut x = x;
is actually desired?
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 believe that is already covered by the shadow_same lint.
☔ The latest upstream changes (presumably #6389) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
ping from triage @cauebs. Do you have any questions on how to proceed here? |
ping from triage @cauebs. Thanks for contributing Clippy! Sadly this PR didn't have any update in the last 2 weeks. If you have more time to continue working on this, feel free to reopen. |
Closes #1657.
I'm really not sure about the way I organized everything, and I think I might be forgetting some corner cases. Any feedback is welcome.
changelog: none