Skip to content

cargo clippy --fix don't remove redundant mut #14617

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

Open
MCJOHN974 opened this issue Apr 15, 2025 · 5 comments · May be fixed by #14626
Open

cargo clippy --fix don't remove redundant mut #14617

MCJOHN974 opened this issue Apr 15, 2025 · 5 comments · May be fixed by #14626
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@MCJOHN974
Copy link

MCJOHN974 commented Apr 15, 2025

Summary

cargo clippy --fix can autofix more problems

Reproducer

I tried this code:

fn foo(_x: &i32) {}

fn main() {
    let mut x = 5i32;
    foo(&mut x);         // this mut is redundant
}

I expected to see this happen:

cargo clippy --fix removes this redundant mut.

Instead, this happened:

cargo clippy --fix warns about this redundant mut

I don't see any use cases were this mut can make side effects and it is not safe to remove it automatically. Is it just not implemented yet or there are some cases where auto removing this mut can bring side effects?

Version

rustc 1.85.0-nightly (21fe748be 2024-12-11)
binary: rustc
commit-hash: 21fe748be15271ea5804e0507cd699b675efe038
commit-date: 2024-12-11
host: aarch64-apple-darwin
release: 1.85.0-nightly
LLVM version: 19.1.5

Additional Labels

No response

Summary Notes

Generated by triagebot, see help for how to add more

@MCJOHN974 MCJOHN974 added the C-bug Category: Clippy is not doing the correct thing label Apr 15, 2025
@samueltardieu
Copy link
Contributor

This is not a bug, but an enhancement request. You are right, this could be suggested by Clippy, and auto-applied in most (all?) cases.

@rustbot label -C-bug +C-enhancement +good-first-issue

@rustbot rustbot added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy and removed C-bug Category: Clippy is not doing the correct thing labels Apr 15, 2025
@rustbot

This comment has been minimized.

@MCJOHN974
Copy link
Author

Thanks @samueltardieu for your answers! I'd like to try take this one, and since I'm newcomer it may take a time for me, so will appreciate if more experienced contributors won't take this for a while

@MCJOHN974
Copy link
Author

@rustbot claim

github-merge-queue bot pushed a commit that referenced this issue Apr 17, 2025
This will let people [add summary
notes](https://forge.rust-lang.org/triagebot/note.html) to an issue, for
example to add that an issue is best kept for first-timers.

changelog: none

I wanted to use it in
#14617 (comment).
@samueltardieu
Copy link
Contributor

Note for our regular contributors: please keep issues labelled "good-first-issue" for people wanting to dip their toes into Clippy's code with something easy. Feel free to claim them if they haven't found someone in months though.

(I know this is claimed already, I'm testing the note feature)

@rustbot note "Best claimed by first-timers"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants