Skip to content

if-then-panic suggestion is not equivalent for complex conditions #7731

Closed
@ghost

Description

I tried this code:

#![warn(clippy::if_then_panic)]

fn main() {
    if false && false { 
        // comment
        panic!("ABC"); 
    };
}

I expected to see this happen: The suggestion would be equivalent but use assert instead.

Instead, this happened:

 --> src/main.rs:5:5
  |
5 | /     if false && false { 
6 | |         // comment
7 | |         panic!("ABC"); 
8 | |     };
  | |_____^ help: try: `assert!(!false && false, "ABC");`

The suggestion doesn't correctly negate the condition and so changes the logic of the code. My original code will never panic. The suggestion will always panic.

Meta

Rust version (rustc -Vv):

rustc 1.57.0-nightly (fdf65053e 2021-09-07)
binary: rustc
commit-hash: fdf65053e99e8966f9bd83b5a8491326cb33d638
commit-date: 2021-09-07
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

@rustbot label +L-suggestion

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions