Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint variable only ever assigned a single value #4016

Open
oli-obk opened this issue Apr 22, 2019 · 1 comment
Open

Lint variable only ever assigned a single value #4016

oli-obk opened this issue Apr 22, 2019 · 1 comment
Labels
A-lint Area: New lints L-correctness Lint: Belongs in the correctness lint group T-MIR Type: This lint will require working with the MIR

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Apr 22, 2019

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

@oli-obk oli-obk added A-lint Area: New lints L-correctness Lint: Belongs in the correctness lint group labels Apr 22, 2019
@camsteffen camsteffen added the T-MIR Type: This lint will require working with the MIR label Nov 15, 2021
@oxalica
Copy link
Contributor

oxalica commented Jun 15, 2023

Just ran into a similar typo bug. oxalica/nil#92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-correctness Lint: Belongs in the correctness lint group T-MIR Type: This lint will require working with the MIR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants