Skip to content

Bad order-of-operations for clippy::if_then_panic 's code suggestion #7759

Closed
@asomers

Description

@asomers

I tried this code:

        if !std::thread::panicking() && e == Err(Errno::EBADF) {
            panic!("Closing an invalid file descriptor!");
        };

I expected to see this happen: Clippy should warn about "only a panic! in an if-then statement`, and suggest an alternative like:

assert!(!(!std::thread::panicking() && e == Err(Errno::EBADF)), "Closing an invalid file descriptor!");

Instead, this happened: Clippy warned and suggested the following alternative. Notice the lack of parenthesis:

assert!(!!std::thread::panicking() && e == Err(Errno::EBADF), "Closing an invalid file descriptor!");

Meta

Rust version (rustc -Vv):

rustc 1.57.0-nightly (f03eb6bef 2021-10-02)
binary: rustc
commit-hash: f03eb6bef8ced8a243858b819e013b9caf83d757
commit-date: 2021-10-02
host: x86_64-unknown-freebsd
release: 1.57.0-nightly
LLVM version: 13.0.0

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions