-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make integer exponentiation methods unstably const #68978
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
69779b5
to
4ce006b
Compare
I believe the previous code was calling `ops::Add::add` instead of the `+` operator to get this behavior.
4ce006b
to
eadd0cf
Compare
This comment has been minimized.
This comment has been minimized.
eadd0cf
to
7fe5eaf
Compare
r? @oli-obk |
lgtm, we should remove the macro at some point, but that's not really a problem to leave around until someone discovers it. I also don't know about the panic situation in that function. r=me with @scottmcm 's approval on that panic "change" |
I have no horse in this race; I added it because I was asked to do so by @kennytm in #45754 (comment) AFAIK that's just a matter of "use fewer So I think that means |
📌 Commit 7fe5eaf has been approved by |
…-obk Make integer exponentiation methods unstably const cc rust-lang#53718 This makes the following inherent methods on integer primitives into unstable `const fn`: - `pow` - `checked_pow` - `wrapping_pow` - `overflowing_pow` - `saturating_pow` - `next_power_of_two` - `checked_next_power_of_two` - `wrapping_next_power_of_two` Only two changes were made to the implementation of these methods. First, I had to switch from the `?` operator, which is not yet implemented in a const context, to a `try_opt` macro. Second, `next_power_of_two` was using `ops::Add::add` (see the first commit) to "get overflow checks", so I switched to `#[rustc_inherit_overflow_checks]`. I'm not quite sure why the attribute wasn't used in the first place.
Rollup of 5 pull requests Successful merges: - #68705 (Add LinkedList::remove()) - #68945 (Stabilize Once::is_completed) - #68978 (Make integer exponentiation methods unstably const) - #69266 (Fix race condition when allocating source files in SourceMap) - #69287 (Clean up E0317 explanation) Failed merges: r? @ghost
cc #53718
This makes the following inherent methods on integer primitives into unstable
const fn
:pow
checked_pow
wrapping_pow
overflowing_pow
saturating_pow
next_power_of_two
checked_next_power_of_two
wrapping_next_power_of_two
Only two changes were made to the implementation of these methods. First, I had to switch from the
?
operator, which is not yet implemented in a const context, to atry_opt
macro. Second,next_power_of_two
was usingops::Add::add
(see the first commit) to "get overflow checks", so I switched to#[rustc_inherit_overflow_checks]
. I'm not quite sure why the attribute wasn't used in the first place.