Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Jarcho (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 (
|
1de3240 to
9a9bd69
Compare
| let b: u64 = 543534; | ||
| let _ = b.ilog2(); | ||
|
|
||
| let _ = 64 - b.leading_zeros(); // No lint |
There was a problem hiding this comment.
Is it check // No lint
Suppose no need to check this additionally
There was a problem hiding this comment.
The manual ilog2 implementation is bit_width - 1 - x.leading_zeros() so this is just making sure that any other constant besides bit_width - 1 does not lint.
|
☔ The latest upstream changes (presumably #13247) made this pull request unmergeable. Please resolve the merge conflicts. |
839539b to
8107d51
Compare
|
☔ The latest upstream changes (presumably #12987) made this pull request unmergeable. Please resolve the merge conflicts. |
8107d51 to
fc5f870
Compare
Jarcho
left a comment
There was a problem hiding this comment.
This will need macro checks. in_external_macro combined with context checks should work (span.ctxt() should be the same for all involved expressions).
Otherwise just a couple of small nits and the test looks like it needs to be re-blessed..
| if !self.msrv.meets(msrvs::MANUAL_ILOG2) { | ||
| return; | ||
| } | ||
| let mut applicability = Applicability::MachineApplicable; |
There was a problem hiding this comment.
It's better to check the HIR tree first.
| } | ||
|
|
||
| if let ExprKind::MethodCall(method_name, reciever, args, _) = expr.kind | ||
| && method_name.ident.as_str() == "ilog" |
There was a problem hiding this comment.
The string check should be moved to after others. It requires locking the symbol table.
| } | ||
| } | ||
|
|
||
| if let ExprKind::MethodCall(method_name, reciever, args, _) = expr.kind |
There was a problem hiding this comment.
Use [arg] instead to save the length check later.
| && args.len() == 1 | ||
| && let ExprKind::Lit(lit) = args[0].kind | ||
| && let LitKind::Int(Pu128(2), _) = lit.node | ||
| && cx.typeck_results().expr_ty(reciever).is_integral() |
There was a problem hiding this comment.
This should be a check for an inherent method rather than just a type check (could be a trait function with the same name). You can add is_inherent_method_call.
| && let ExprKind::Lit(lit) = left.kind | ||
| && let LitKind::Int(Pu128(val), _) = lit.node | ||
| && let ExprKind::MethodCall(method_name, reciever, _, _) = right.kind | ||
| && method_name.ident.as_str() == "leading_zeros" |
There was a problem hiding this comment.
This will also need a check for an inherent method.
|
☔ The latest upstream changes (presumably #13322) made this pull request unmergeable. Please resolve the merge conflicts. |
a0ba2b5 to
bd65f17
Compare
|
☔ The latest upstream changes (presumably #13334) made this pull request unmergeable. Please resolve the merge conflicts. |
|
☔ The latest upstream changes (possibly d28d234) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Ping @Sour1emon from triage. Do you intend to keep working on this? |
|
At the moment I do not have time to finish it. |
changelog: new lint: [
manual_ilog2]Suggest using
ilog2()instead of the manual implementations for some basic casesPart of #12894