Make integer exponentiation methods unstably const#68978
Merged
bors merged 4 commits intorust-lang:masterfrom Feb 20, 2020
Merged
Make integer exponentiation methods unstably const#68978bors merged 4 commits intorust-lang:masterfrom
bors merged 4 commits intorust-lang:masterfrom
Conversation
Contributor
|
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
Contributor
Author
Contributor
|
r? @oli-obk |
Contributor
|
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" |
Member
|
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 |
Collaborator
|
📌 Commit 7fe5eaf has been approved by |
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this pull request
Feb 20, 2020
…-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.
This was referenced Feb 20, 2020
bors
added a commit
that referenced
this pull request
Feb 20, 2020
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
59 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cc #53718
This makes the following inherent methods on integer primitives into unstable
const fn:powchecked_powwrapping_powoverflowing_powsaturating_pownext_power_of_twochecked_next_power_of_twowrapping_next_power_of_twoOnly 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_optmacro. Second,next_power_of_twowas 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.