Skip to content

needless_bool triggers on cfg! comparisons #3973

Closed
@nbaksalyar

Description

@nbaksalyar

Clippy gives wrong suggestions if there's a bool comparison with a result of cfg!(...) macro, e.g. testing for a feature flag:

error: inequality checks against false are unnecessary
  --> safe_core/src/ipc/mod.rs:86:8
   |
86 |     if mock != cfg!(feature = "use-mock-routing") {
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `mock`
   |

If I try to compile with the future switched on (cargo build --features use-mock-routing), it gives an opposite suggestion:

error: inequality checks against true can be replaced by a negation
  --> safe_core/src/ipc/mod.rs:86:8
   |
86 |     if mock != cfg!(feature = "use-mock-routing") {
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!mock`
   |

Version:

$ cargo clippy -V
clippy 0.0.212 (1fac380 2019-02-20)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingL-suggestionLint: Improving, adding or fixing lint suggestionsT-macrosType: Issues with macros and macro expansiongood 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