Skip to content
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

self doesn't need to be mutable lint #9591

Closed
Detector-I opened this issue Oct 4, 2022 · 1 comment · Fixed by #12693
Closed

self doesn't need to be mutable lint #9591

Detector-I opened this issue Oct 4, 2022 · 1 comment · Fixed by #12693
Labels
A-lint Area: New lints

Comments

@Detector-I
Copy link

What it does

Having a function with &mut self as an argument, and actually never use self as mutable inside it wont give us any compiler or clippy warning...
here is an example

fn method(&mut self) -> String {
    self.a_str.to_string()
}

I think in this case clippy should say self doesn't need to be mutable.

Lint Name

unused_mutable_self

Category

correctness

Advantage

  • self wont be borrowed anymore in this function when its dont needed

Drawbacks

No response

Example

fn method(&mut self) -> String {
    self.a_str.to_string()
}

Could be written as:

fn method(&self) -> String {
    self.a_str.to_string()
}
@Detector-I Detector-I added the A-lint Area: New lints label Oct 4, 2022
@Detector-I Detector-I changed the title self doesn't need to be mutable and unused self self doesn't need to be mutable lint Oct 4, 2022
@kraktus
Copy link
Contributor

kraktus commented Oct 4, 2022

Same as #5546 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
2 participants