rust-lang / rust-lang/rust-clippy
nonminimal_bool and is_x86_feature_detected
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the nonminimal_bool lint and reproduce the warning using the Rust Playground example that chains is_x86_feature_detected!(). Inspect how the macro is handled and how the suggestion is generated; done means the lint no longer emits invalid Rust for this case, either by producing a valid suggestion or skipping the warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100