Always true/always false comparison lint

Open
#13,280 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
tooling

Research direction

Start with the Rust example in issue #13280 and compare its always-true and always-false cases with the related issue #13279. Define the intended lint behavior from those examples, then determine the relevant Clippy lint entry point and tests; done means the stated dead comparisons are diagnosed without incorrectly removing required control flow.

Written by the indexing model from the issue text.

Description

A-lint
What it does

Spots dead if tests, where their comparison didn't change.

Advantage

To produce cleaner, shorter code, that sometimes otherwise hides bugs.

Drawbacks

No response

Example
#![warn(clippy::all)]
#![warn(clippy::nursery)]
#![warn(clippy::pedantic)]

const fn foo(x: u32) {
    let y = x;
    loop {
        if x == y { break; }
    }
}

fn main() {
    foo(20);
}

Could be written as code without the comparison that's always true (so it always breaks, so you can't just remove that line):

if x == y {...}

(Related to issue #13279).

Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

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.

More from rust-lang/rust-clippy

All issues in rust-lang/rust-clippy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.