rust-lang / rust-lang/rust-clippy

conditions that are always true or false

Open
#8,938 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What it does

It would be great if clippy could somehow try to const-eval expressions in conditions and warn if they always return true/false.

Lint Name

?

Category

suspicious, complexity

Advantage

This could find logic bugs for example

Drawbacks

No response

Example
#![feature(inline_const)]

const X: [i32; 7] = [1, 2, 3, 4, 5, 6, 9];

pub fn main() {
    // always true
    if const { X[1] == 2 } {}

    // always false
    if const { X[0] == X[4] } || 2 == X[0] {}

}

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

The issue names no files, tests, or entry points. Start by reviewing the proposed Rust examples and the requested suspicious/complexity categories, then identify the appropriate Clippy lint design and validation path; done means warning when the shown conditions always evaluate true or false.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
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.