rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

conditions that are always true or false

Open matthiaskrgr opened this issue 2 years ago • 0 comments

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] {}

}

matthiaskrgr avatar Jun 03 '22 23:06 matthiaskrgr