rust-lang / rust-lang/rust-clippy

Lint variable only ever assigned a single value

Open
#4,016 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint L-correctness T-MIR
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

In both the rust source and the rustfmt source I encountered code of the sort

let first = false;
for x in y {
    if first {
        first = false;
        // do some logic
    }
    // do some logic
}

If a variable never gets a mutable reference taken to and all assignments assign the same value, we should have a correctness lint tell the user they are doing something that makes no sense in any program.

This is probably easiest implemented as an MIR lint

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

Review the Rust source and rustfmt source examples described in the issue, then investigate the MIR lint entry points. Define how to detect variables whose assignments always use the same value and how the correctness lint should report them; done means the behavior is covered by appropriate lint tests.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.