Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
asomers opened this issue Oct 3, 2021 · 1 comment
Closed
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@asomers
Copy link

asomers commented Oct 3, 2021

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

@asomers asomers added the C-bug Category: Clippy is not doing the correct thing label Oct 3, 2021
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Oct 3, 2021
@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label Oct 4, 2021
@giraffate
Copy link
Contributor

This was fixed at #7741, so I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

3 participants