feat(manual_ilog2): new lint#15865
Conversation
|
@Jarcho you might be interested in this as you reviewed the original PR |
|
r? clippy |
clippy_lints/src/manual_ilog2.rs
Outdated
| // Whether `leading_zeros` is an inherent method, i.e. doesn't come from some unrelated trait | ||
| && cx.ty_based_def(right).opt_parent(cx).is_impl(cx) |
There was a problem hiding this comment.
I believe this wouldn't catch that since a trait impl is also a DefKind::Impl. I think it's fine without the check though since inherent methods come first in method resolution
There was a problem hiding this comment.
Oh, it looks like you're right; I'll remove the call then.
The reason I wrote it that way is that that's what is_inherent_method_call was replaced with in https://github.com/rust-lang/rust-clippy/pull/15682/files#diff-9d3f62135af85bbb426d0e358666790f639f6777c8dc504a7527e2bc7f830fb1R741, and so I assumed it would only match, well, inherent method calls. @Jarcho maybe this should be a separate method, something like is_inherent_impl?
There was a problem hiding this comment.
TypeckResults always has things resolved to either the inherent item or the trait item, but never a trait impl item. Checking that the parent is an impl is enough because of this.
This comment has been minimized.
This comment has been minimized.
clippy_lints/src/manual_ilog2.rs
Outdated
| && ilog.ident.name == sym::ilog | ||
| && let ExprKind::Lit(lit) = two.kind | ||
| && let LitKind::Int(Pu128(2), _) = lit.node | ||
| && cx.typeck_results().expr_ty(recv).is_integral() |
There was a problem hiding this comment.
This should be the adjusted type. You want the type passed in to the method.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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. |
ac35c0e to
d9cc76a
Compare
clippy_lints/src/manual_ilog2.rs
Outdated
| /// Checks for expressions like `31 - x.leading_zeros()` which are manual | ||
| /// reimplementations of `x.ilog2()` |
There was a problem hiding this comment.
I think it's worth mentioning the type here so that it's clear the 31 is for u32 only
There was a problem hiding this comment.
Added a (somewhat wordy) note
|
I was looking at the wrong diff |
Revival of #13331
Part of #12894
changelog: [
manual_ilog2]: new lint