Skip to content

self doesn't need to be mutable lint #9591

Closed
@Detector-I

Description

@Detector-I

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()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions