rust-lang / rust-lang/rust-clippy
Suggest the use of the std lib blsi instruction
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
It spots another coding pattern that's better replaced by a single std lib function.
Advantage
It avoids casts, and makes the code intent clear, removing the need of some code comments too.
Drawbacks
Translating Rust code to other languages could require a bit more work.
Example
fn foo1(i: u64) -> u64 {
let si = i.cast_signed();
i - (-si & si).cast_unsigned()
}
Could be written with the explicit call to the blsi CPU instruction (sometimes LLVM doesn't use blsi in similar cases):
#![feature(isolate_most_least_significant_one)]
fn foo2(i: u64) -> u64 {
i - i.isolate_least_significant_one()
}
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
No files, tests, or entry points are named. Start by locating related Clippy lints for bit-operation patterns and their tests, then use the two Rust examples to define the expected match and suggestion; done means the lint handles the shown pattern and verifies its diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100