-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[feat]: make unnecessary_mut_passed lint auto applicable
#14626
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
base: master
Are you sure you want to change the base?
Conversation
|
r? @Alexendoo rustbot has assigned @Alexendoo. Use |
| let snippet = snippet(cx, argument.span, ".."); | ||
| let trimmed_snippet = &snippet[5..]; |
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.
Cursory review:
It would probably be best if you use span_lint_and_then(), with .span_suggestion() (or .span_suggestion_verbose(), whether this gives a prettier result or not), and propose to rewrite &mut as &, instead of reconstructing the snippet. You can proceed as follows:
- The span to replace is from the start of
argumentto the start of theAddrOfargument. - You should also ensure that the context of
argumentis the same one as the context of theAddrOfargument, to ensure that the&muthas not been built by a macro. - Add tests where
&mutcomes from a macro for example (build a macrorefmutand callrefmut!(variable)), and where the expression comes from a macro (build a macroidentityand call&mut identity!(var)).
Also, in the PR message (changelog) and title, you should use the lint name in lower case.
|
Also, are the tests I edited enough, or clippy have some tests to check if lint actually is machine-applicable and is applied correctly ? |
UNNECESSARY_MUT_PASSED lint auto applicableunnecessary_mut_passed lint auto applicable
|
You can remove this rust-clippy/tests/ui/mut_reference.rs Line 2 in 6ab0b14
.fixed file when you cargo uibless it
|
|
☔ The latest upstream changes (possibly 32a3744) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Ping @MCJOHN974 from triage. Do you plan to return to working on this? |
|
Hi @MCJOHN974, it turns out I've implemented the exact same thing in #15438, because I learned about this issue from #8943 instead of #14617 and thus didn't know it was supposed to be left to first-time contributors -- sorry about that.. |
Description
Make [
unnecessary_mut_passed] auto applicable and automatically fixable viacargo clippy --fixWhy it is necessary
There is no case where auto-applying this lint can harm, and it is always nice to have lint applied automatically.
fixes #14617
Checklist
.stderrfile) and make them passingcargo testpasses locallycargo dev update_lintscargo dev fmtDisclaimer
It's my first PR in clippy, so sorry if my PR deviates from any guidelines or traditions, and thanks you for the feedback!