Skip to content

Lint variable only ever assigned a single value #4016

Open
@oli-obk

Description

@oli-obk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-correctnessLint: Belongs in the correctness lint groupT-MIRType: This lint will require working with the MIR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions