Skip to content

lengyijun/explicit_reinitialization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

explicit_reinitialization

Start

install dylint

cargo dylint --git https://github.com/lengyijun/explicit_reinitialization/

What it does

If a reinitialization dominate all reachable usages, a fresh variable should be introduced.

Make rust more functional programming.

Why is this bad?

Introduce unnecessary mut. Not good in jumping to definition in ide.

Known problems

  1. Known false positive and false negative: see test
  2. 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

Example

let mut x = 1;
println!("{x}");
x = 2;
println!("{x}");

Use instead:

let mut x = 1;
println!("{x}");
let x = 2;
println!("{x}");

Reference

rust-lang/rust-clippy#11687

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages