New lint: bitwise_not_zero, rewrite !0 as {int}::MAX#16806
New lint: bitwise_not_zero, rewrite !0 as {int}::MAX#16806nik-rev wants to merge 1 commit intorust-lang:masterfrom
bitwise_not_zero, rewrite !0 as {int}::MAX#16806Conversation
|
rustbot has assigned @samueltardieu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
df6f69d to
beb9d9a
Compare
|
Lintcheck changes for 1acfd24
This comment will be updated if you push new changes |
95ec375 to
299fac0
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5c65746 to
5620a80
Compare
This comment has been minimized.
This comment has been minimized.
ec2a486 to
6769831
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| "usage of the bitwise not `!` on zero", | ||
| "this is clearer written as the maximum value", | ||
| format!("{integer}::MAX"), | ||
| Applicability::MaybeIncorrect, |
There was a problem hiding this comment.
It suggests to rewrite with u32::MAX, but someone may not have that in scope. e.g. they might define struct u32;
|
Reminder, once the PR becomes ready for a review, use |
|
This lint has been nominated for inclusion. |
4a63587 to
469ad15
Compare
bitwise_not_zero, rewrite !0 as i32::MAXbitwise_not_zero, rewrite !0 as {int}::MAX
f9dd43d to
91d9717
Compare
b8c7588 to
441cc5d
Compare
Co-authored-by: Samuel Tardieu <sam@rfc1149.net> Co-authored-by: Ada Alakbarova <58857108+ada4a@users.noreply.github.com>
441cc5d to
1acfd24
Compare
|
@rustbot ready |
This lint suggests to rewrite expressions like:
As:
Because
!0is confusing, it performs the bitwise NOT operator, equivalent to specifying theMAXvalue.changelog: [
bitwise_new_lint]: added lint that replaces!0with{int}::MAX