Skip to content

Unreachable code warning missing at if expression with false condition #87239

Open
@gheoan

Description

@gheoan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-unreachable_codeLint: unreachable_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions