Skip to content

bool_comparison triggers twice on the same code #15367

@samueltardieu

Description

@samueltardieu

Summary

The same lint triggers twice on the same code fragment.

Reproducer

I tried this code:

#![allow(dead_code)]
#![allow(clippy::nonminimal_bool)]
#![warn(clippy::bool_comparison)]

fn f(a: bool) -> bool {
    !a == false
}

fn main() {}

I expected to see this happen: a warning for !S == false.

Instead, this happened: two warnings from the same lint.

warning: this comparison might be written more concisely
 --> /tmp/v.rs:6:5
  |
6 |     !a == false
  |     ^^^^^^^^^^^ help: try simplifying it as shown: `a != false`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
note: the lint level is defined here
 --> /tmp/v.rs:3:9
  |
3 | #![warn(clippy::bool_comparison)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^

warning: equality checks against false can be replaced by a negation
 --> /tmp/v.rs:6:5
  |
6 |     !a == false
  |     ^^^^^^^^^^^ help: try simplifying it as shown: `!!a`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison

warning: 2 warnings emitted

Note that !!a will be replaced by a in the suggestion when #15366 is merged.

Version

rustc 1.86.0 (05f9846f8 2025-03-31) (built from a source tarball)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingD-confusingDiagnostics: Confusing error or lint that should be reworked.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions