rust icon indicating copy to clipboard operation
rust copied to clipboard

Unreachable code warning missing at if expression with false condition

Open gheoan opened this issue 3 years ago • 0 comments

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6526368602dd7742a2bd1d988fe03f66

let a: u32 = 3;
if a < a {
    panic!();
}
    
if 3 > 3 {
    panic!(); 
}

if false {
    panic!();
}

The current output is: nothing Can be reproduced on versions 1.55-nightly and 1.53.

Ideally this code should trigger the unreachable_code lint at least in the case when an integer variable is compared with itself, to prevent mistakes such as typos. AFAIK, this code is eliminated when optimizations are turned on, so the warning should follow along.

I'm not sure if the case when the conditional expression is exactly false should be considered a warning, since it is probably not a mistake.

@rustbot modify labels: +A-lint

gheoan avatar Jul 18 '21 02:07 gheoan