rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.47k stars 1.55k forks source link

Lint useless shadowing #11704

Open miguelraz opened 1 year ago

miguelraz commented 1 year ago

What it does

Shadowing let x and then let mut x bindings with no intermediate uses of x could be combined to a single statement.

Advantage

Drawbacks

No response

Example


fn foo() -> i32 {
    let x = 6;
    let mut x = x;
    x += 1;
    x
}

Could be written as:

fn foo() -> i32 {
    let mut x = 6;
    x += 1;
    x
}
miguelraz commented 1 year ago

If this is greenlit for contribution, I would not mind spearheading the implementation as a first contribution to clippy.