Lint bit width#16902
Conversation
|
r? @dswij rustbot has assigned @dswij. Use Why was this reviewer chosen?The reviewer was selected based on:
|
8b811db to
236b137
Compare
| ty::Uint(ty::UintTy::Usize) => Some(cx.tcx.data_layout.pointer_size().bits()), | ||
| ty::Uint(uint_ty) => uint_ty.bit_width(), |
There was a problem hiding this comment.
Same as in the previous comment
|
|
Good catch! I remove support |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Sorry for the delay. Overall it looks good, just a small comment and waiting FCP.
@rustbot label lint-nominated
|
This lint has been nominated for inclusion. |
You could solve this by suggesting |
|
Reminder, once the PR becomes ready for a review, use |
966cd22 to
f2d90b9
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. |
@ada4a fair point, I will look into this over the week. In case this make sense I maybe put the changes on a separate PR, on top of this one. What do you think? :) |
Hm, I'm not fundamentally opposed to the idea – a smaller PR is easier to get merged – but given that the FCP usually takes ~2 weeks anyway, we might as well use the time to bring that new pattern in, as I don't think it's very controversial. I'd say try implementing the nonzero thing (at your own pace); if you see that that requires a large restructuring of the lint, then consider squashing that change into this PR – because it'd be silly to have a reviewer approve the code just for it to get changed right after; otherwise, feel free to leave it as a separate PR |
Fixes #16876
Current state:
T::BITS - x.leading_zeros()for uintssuggests change of(see comment)NonZero::<T>::BITS - x.leading_zeros()for NonZeroDescription
rust 1.97 introduces the method
bit_width()for uints and NonZero (docs), this will make the manual computation redundant and unnecessary.Example
Can be replaced with:
changelog: [manual_bit_width]: Added a lint to detect bit_width implementations.
I have
.stderrfile)cargo testpasses locallycargo dev update_lintscargo dev fmt