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

nonminimal_bool and is_x86_feature_detected #14153

Open
GoldsteinE opened this issue Feb 5, 2025 · 0 comments
Open

nonminimal_bool and is_x86_feature_detected #14153

GoldsteinE opened this issue Feb 5, 2025 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied T-macros Type: Issues with macros and macro expansion

Comments

@GoldsteinE
Copy link

Summary

nonminimal_bool fires when chaining is_x86_feature_detected!(), suggesting invalid code.

Lint Name

nonminimal_bool

Reproducer

I tried this code:

pub fn check() -> bool {
    std::is_x86_feature_detected!("sse4.2") || std::is_x86_feature_detected!("avx2")
}

(playground)

I saw this happen:

warning: this boolean expression can be simplified
 --> src/lib.rs:2:5
  |
2 |     std::is_x86_feature_detected!("sse4.2") || std::is_x86_feature_detected!("avx2")
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
  = note: `#[warn(clippy::nonminimal_bool)]` on by default
help: try
  |
2 |     !(!cfg!(target_feature = $target_feature_lit) && !$crate::detect::__is_feature_detected::$feature() && !$crate::detect::__is_feature_detected::$feature())
  |
2 |     std::is_x86_feature_detected!("sse4.2") || std::is_x86_feature_detected!("sse4.2") || std::is_x86_feature_detected!("avx2")
  |

I expected to see this happen:

I think clippy tries to tell me that avx2 implies sse4.2, so there’s no need to specify both. The output is extremely confusing though, and the suggestion is not valid Rust. I think either it should suggest correcting to just std::is_x86_feature_detected!("avx2") (although I’m not sure this could be reasonably implemented), or just skip this warning.

This reproduces on the latest nightly in Playground. It may be related to #12627, but I’m not sure if it’s a duplicate.

Version

rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5

Additional Labels

@rustbot label +I-suggestion-causes-error +T-macros

@GoldsteinE GoldsteinE added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 5, 2025
@rustbot rustbot added I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied T-macros Type: Issues with macros and macro expansion labels Feb 5, 2025
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 I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

No branches or pull requests

2 participants