Skip to content

Lint needless &mut when & suffices #1230

Open
@phil-opp

Description

@phil-opp

Idea: Add a lint for unneeded mutable borrows when an immutable borrow suffices:

fn main() {
    let m = &mut 21; // `&21` would suffice
    println!("{}", m);
}

This lint could also catch an unneeded ref mut when a plain ref suffices:

fn main() {
    let test = &mut Test{a: 1};
    let &mut Test{ ref mut a } = test;

    println!("{}", a);
}

struct Test {
    a: i32,
}

cc @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions