Skip to content

new lint: unnecessary_ref_mut #12361

Open
@TennyZhuang

Description

@TennyZhuang

What it does

Check value that are matched by ref mut but only immutable methods are called.

Advantage

  • Reduce unnecessary mutability

Drawbacks

No response

Example

struct S;
impl S {
    fn f(&self) {}
}
fn main() {
    let mut x = Some(S);
    if let Some(ref mut y) = x {
        y.f();
    }
}

Could be written as:

struct S;
impl S {
    fn f(&self) {}
}
fn main() {
    let mut x = Some(S);
    if let Some(ref y) = x {
        y.f();
    }
}

Metadata

Metadata

Assignees

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