-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[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
argument
to the start of theAddrOf
argument. - You should also ensure that the context of
argument
is the same one as the context of theAddrOf
argument, to ensure that the&mut
has not been built by a macro. - Add tests where
&mut
comes from a macro for example (build a macrorefmut
and callrefmut!(variable)
), and where the expression comes from a macro (build a macroidentity
and 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. |
Description
Make [
unnecessary_mut_passed
] auto applicable and automatically fixable viacargo clippy --fix
Why 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
.stderr
file) and make them passingcargo test
passes locallycargo dev update_lints
cargo dev fmt
Disclaimer
It's my first PR in clippy, so sorry if my PR deviates from any guidelines or traditions, and thanks you for the feedback!