Skip to content

Unecessary mut reference in parameter #8863

Closed
@emilk

Description

@emilk

What it does

It warns against using &mut in an parameter where & would suffice.

Lint Name

unnecessary-mut-ref

Category

suspicious

Advantage

Less mut means less fights with the borrow checker. It can also lead to more opportunities for parallelization.

This lint could also catch bugs where the user intended to mutate an argument but forgot too.

Drawbacks

A user may want to create an API where they reserve the right to mutate an argument, but does not do so yet.

We should not warn when implementing a trait.

Example

fn foo(&mut self, y: &mut i32) -> i32 {
    self.x + *y
}

Could be written as:

fn foo(&self, y: &i32) -> i32 {
    self.x + *y
}

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