Skip to content

Conversation

@ada4a
Copy link
Contributor

@ada4a ada4a commented Oct 11, 2025

Revival of #13331

Part of #12894

changelog: [manual_ilog2]: new lint

@rustbot rustbot added needs-fcp S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 11, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 11, 2025

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@ada4a
Copy link
Contributor Author

ada4a commented Oct 11, 2025

@Jarcho you might be interested in this as you reviewed the original PR

@dswij
Copy link
Member

dswij commented Oct 31, 2025

r? clippy

@rustbot rustbot assigned Alexendoo and unassigned dswij Oct 31, 2025
Comment on lines 68 to 69
// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Alexendoo Alexendoo added S-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties needs-fcp labels Oct 31, 2025
@Alexendoo
Copy link
Member

Opened https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/FCP.20manual_ilog2/with/548234188

@rustbot

This comment has been minimized.

&& 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the adjusted type. You want the type passed in to the method.

@rustbot

This comment has been minimized.

Copy link
Contributor

@teofr teofr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be a separate PR, but it'd be quite easy to also lint x.checked_ilog(2) into x.checked_ilog2()

View changes since this review

Comment on lines +74 to +75
&& self.msrv.meets(cx, msrvs::ILOG2)
&& !is_from_proc_macro(cx, expr) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this to the start of the function, since they're really not part of the 31 - x.leading_zeros() case.

Idem below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would remove some duplication, yes, but the problem is that both of these checks are rather expensive:

  • the MSRV check requires walking up through all the attributes, and I think also going through the Clippy config
  • the proc macro check is very expensive I'm told (though I'm not completely sure why), and so it should generally be the last if of any lint

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks aren't first in general as a perf thing. They're bad filters in general and neither are fast.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, sorry for the noise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good!

@rustbot

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Nov 2, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp S-final-comment-period Status: final comment period it will be merged unless new objections are raised (~1 week)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants