Open
Description
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")
}
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