rust-lang / rust-lang/rust-clippy

reinitialization with let

Open
#11,671 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #11687 by @lengyijun — closed without merging
A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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); 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the issue's Rust examples and the linked pull request #11687 to understand the proposed reinitialization behavior. Determine the intended lint scope, its handling of dominance and later bindings, and the tests needed to establish when the transformation is valid; done means the behavior and acceptance criteria are agreed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.