Conversation
|
r? @Nilstrieb rustbot has assigned @Nilstrieb. Use |
This comment has been minimized.
This comment has been minimized.
|
r? libs-api |
|
I recommend you open an API Change Proposal as described here, it's a more efficient way to get the libs-api team to decide on whether this should be accepted or not: https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html |
|
The original |
|
ACP accepted rust-lang/libs-team#391 (comment) @rustbot ready |
|
@rustbot label -S-waiting-on-ACP |
library/core/src/num/uint_macros.rs
Outdated
| pub const fn checked_ilog2(self) -> Option<u32> { | ||
| // FIXME: Simply use `NonZero::new` once it is actually generic. | ||
| if let Some(x) = <$NonZeroT>::new(self) { | ||
| if let Some(x) = NonZero::new(self) { |
There was a problem hiding this comment.
Maybe change these to match rather than if let, to be consistent with the new isqrt? Or even .map(NonZero::<Self>::ilog10).
There was a problem hiding this comment.
Option::map is not const (not even unstably). match does look a bit nicer though.
library/core/src/num/nonzero.rs
Outdated
| unsafe { | ||
| hint::assert_unchecked(res < 1 << (Self::BITS / 2)); | ||
| } |
There was a problem hiding this comment.
| unsafe { | |
| hint::assert_unchecked(res < 1 << (Self::BITS / 2)); | |
| } | |
| unsafe { hint::assert_unchecked(res < 1 << (Self::BITS / 2)) }; |
Extremely minor nit but semi usually looks nicer outside single-line braced blocks
2f3501e to
8234581
Compare
|
@rustbot author |
|
@rustbot ready |
|
☔ The latest upstream changes (presumably #126914) made this pull request unmergeable. Please resolve the merge conflicts. |
Implements #70887 (comment), with the following signature:
Unintended benefits include one fewer panicking branch in
ilog2for LLVM to optimize away, and one fewerassume_uncheckedasNonZeroalready does that.The fast path for
self == 1is dropped, but the current implementation is very slow anyways compared to hardware. Performance improvements can always come later.(I didn't add the function to
NonZero<iN>, since every existingNonZeromethod is non-panicking, and it might be nice to leave it that way.)