Skip to content

reinitialization with let #11671

@lengyijun

Description

@lengyijun

What it does

If an assignment dominate all usages where it can reach, assignment can be replaced by a let bind, instead of overwrite

Advantage

  • less mut
  • like functional programming
  • explicit dominance
  • helpful in jumpping to definition in ide

Drawbacks

None (not sure)

Example

 let mut x = "hello".to_string();
    let mut y = vec![];

    y.push(x);

    x = "goodbye".to_string();

    println!("{}", x); 

Could be written as:

 let mut x = "hello".to_string();
    let mut y = vec![];

    y.push(x);

    let x = "goodbye".to_string();

    println!("{}", x); 

Metadata

Metadata

Assignees

No one assigned

    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