install dylint
cargo dylint --git https://github.com/lengyijun/explicit_reinitialization/
If a reinitialization dominate all reachable usages, a fresh variable should be introduced.
Make rust more functional programming.
Introduce unnecessary mut. Not good in jumping to definition in ide.
- Known false positive and false negative: see test
- increase the peak memory usage
let mut x = vec![1, 2, 3];
x = vec![4, 5, 6]; // x is dropped here
// let x = vec![4, 5, 6]; // x is no longer dropped here, but at the end of the scope
let mut x = 1;
println!("{x}");
x = 2;
println!("{x}");
Use instead:
let mut x = 1;
println!("{x}");
let x = 2;
println!("{x}");