Add manual_isolate_lowest_one lint#17037
Conversation
|
rustbot has assigned @samueltardieu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Reminder, once the PR becomes ready for a review, use |
bdc6c6b to
45572cf
Compare
|
Addressed review feedback in 45572cf:
Verification run locally:
@rustbot ready |
45572cf to
4525d1b
Compare
|
Added explicit MSRV compatibility coverage in
Local focused verification:
@rustbot ready |
4525d1b to
af1af72
Compare
|
Addressed the latest review in af1af72.
Verification after the changes:
@rustbot ready |
af1af72 to
a9f8638
Compare
|
I have addressed the latest review in a9f8638. based on @samueltardieu comments:
Fresh verification after the patch:
@rustbot ready |
a9f8638 to
029457b
Compare
|
Small follow-up for CI: Additional verification:
|
View all comments
changelog: new lint: [
manual_isolate_lowest_one]Adds a new
manual_isolate_lowest_onelint for manual lowest-set-bit isolation patterns that can be written with.isolate_lowest_one().This detects simple local expressions in the following forms:
x & x.wrapping_neg()x.wrapping_neg() & xx & -xfor signed integers-x & xfor signed integersnz.get() & nz.get().wrapping_neg()forNonZero<T>integer localsnz.get() & -nz.get()for signedNonZero<T>integer localsThe implementation intentionally limits suggestions to simple local paths so rustfix does not change evaluation count for non-trivial expressions. For
NonZero<T>::get()forms, the suggestion preserves the original primitive result type by usingnz.isolate_lowest_one().get().Validation:
cargo fmtcargo check -p clippy_lintsTESTNAME=manual_isolate_lowest_one cargo uitestcargo dev fmt --checkgit diff --checkNote:
cargo test --test dogfoodwas attempted locally but hit the existing Windowstikv_jemalloc_syscrate resolution issue before reaching a PR-specific failure. The focused lint UI test andclippy_lintscheck pass.