rust-lang / rust-lang/rust-clippy

Suggest the use of the std lib blsi instruction

Open
#14,380 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.