-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new lint manual_is_power_of_two
#13327
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
☔ The latest upstream changes (presumably #13247) made this pull request unmergeable. Please resolve the merge conflicts. |
&& let ExprKind::Lit(lit1) = right.kind | ||
&& let LitKind::Int(Pu128(0), _) = lit1.node | ||
{ | ||
let snippet = snippet_with_applicability(cx, left1.span, "..", &mut applicability); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might make sense combine sugg and span_lint_and_sugg here and 48-58 so change in one place if needed
|
||
let b = 4_i64; | ||
|
||
// is_power_of_two only works for unsigned integers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good idea mentioned about this at lint doc as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some duplication and the binary operations might be reversed. Either you implement the tests for both directions or you document the missing cases in the lint docs under # Known Problems
and we can open an issue to amend the lint later. Both are fine.
☔ The latest upstream changes (presumably #12987) made this pull request unmergeable. Please resolve the merge conflicts. |
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits: |
Co-authored-by: Ruby Lazuli <[email protected]>
Co-authored-by: Ruby Lazuli <[email protected]>
if let ExprKind::MethodCall(method_name, reciever, _, _) = left.kind | ||
&& method_name.ident.as_str() == "count_ones" | ||
&& let &Uint(_) = cx.typeck_results().expr_ty(reciever).kind() | ||
&& check_lit(right, 1) | ||
{ | ||
build_sugg(cx, expr, reciever, &mut applicability); | ||
} | ||
|
||
// 1 == a.count_ones() | ||
if let ExprKind::MethodCall(method_name, reciever, _, _) = right.kind | ||
&& method_name.ident.as_str() == "count_ones" | ||
&& let &Uint(_) = cx.typeck_results().expr_ty(reciever).kind() | ||
&& check_lit(left, 1) | ||
{ | ||
build_sugg(cx, expr, reciever, &mut applicability); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can loop over [(left, right), (right, left)] to reduce the code duplication here and elsewhere.
Apart from a good deal of code duplication, this seems good to merge, we can refactor in a followup PR later. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Suggest using
is_power_of_two()
instead of the manual implementations for some basic casesPart of #12894
changelog: new [
manual_is_power_of_two
] lint