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

needless_bool triggers on cfg! comparisons #3973

Closed
nbaksalyar opened this issue Apr 16, 2019 · 3 comments · Fixed by #6211
Closed

needless_bool triggers on cfg! comparisons #3973

nbaksalyar opened this issue Apr 16, 2019 · 3 comments · Fixed by #6211
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 L-suggestion Lint: Improving, adding or fixing lint suggestions T-macros Type: Issues with macros and macro expansion

Comments

@nbaksalyar
Copy link

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)
@flip1995 flip1995 added L-suggestion Lint: Improving, adding or fixing lint suggestions good-first-issue These issues are a good way to get started with Clippy C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion labels Apr 16, 2019
@flip1995
Copy link
Member

To fix this, the span of the bool literal needs to be checked if it comes from a macro expansion.

@nbaksalyar
Copy link
Author

I can give it a try. Thanks! :)

@flip1995
Copy link
Member

Let me know if you need any help.

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 L-suggestion Lint: Improving, adding or fixing lint suggestions T-macros Type: Issues with macros and macro expansion
Projects
None yet
3 participants