Skip to content
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

Tracking Issue for #![feature(mixed_integer_ops)] #87840

Closed
3 tasks done
a1phyr opened this issue Aug 7, 2021 · 11 comments
Closed
3 tasks done

Tracking Issue for #![feature(mixed_integer_ops)] #87840

a1phyr opened this issue Aug 7, 2021 · 11 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@a1phyr
Copy link
Contributor

a1phyr commented Aug 7, 2021

Feature gate: #![feature(mixed_integer_ops)]

Public API

// `uX` is `u8`, `u16`, `u32`, `u64`,`u128`, `usize`
impl uX {
    pub const fn checked_add_signed(self, iX) -> Option<Self>;
    pub const fn overflowing_add_signed(self, iX) -> (Self, bool);
    pub const fn saturating_add_signed(self, iX) -> Self;
    pub const fn wrapping_add_signed(self, iX) -> Self;
}

impl iX {
    pub const fn checked_add_unsigned(self, uX) -> Option<Self>;
    pub const fn overflowing_add_unsigned(self, uX) -> (Self, bool);
    pub const fn saturating_add_unsigned(self, uX) -> Self;
    pub const fn wrapping_add_unsigned(self, uX) -> Self;

    pub const fn checked_sub_unsigned(self, uX) -> Option<Self>;
    pub const fn overflowing_sub_unsigned(self, uX) -> (Self, bool);
    pub const fn saturating_sub_unsigned(self, uX) -> Self;
    pub const fn wrapping_sub_unsigned(self, uX) -> Self;
}

Steps / History

@a1phyr a1phyr added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 7, 2021
@leonardo-m
Copy link

Somewhere you should write about use cases & purposes of these ops :)

@brendanzab
Copy link
Member

Somewhere you should write about use cases & purposes of these ops :)

I've needed checked_add_signed for working with io::SeekFrom, for example! Had to roll my own (and I'm not sure how correct it is), inspired by this implementation:

fn checked_add_signed(pos: u64, offset: i64) -> Option<u64> {
    if offset >= 0 {
        u64::checked_add(pos, offset as u64)
    } else {
        u64::checked_sub(pos, offset.unsigned_abs())
    }
}

It would be great to have this in the stdlib!

@a1phyr
Copy link
Contributor Author

a1phyr commented Mar 10, 2022

This is exactly what prompted me to write these !

Also it is what std uses for Cursor now.

@tjallingt
Copy link

tjallingt commented Jun 7, 2022

Would love to see this get stabilized. Not sure what the right process is to start an FCP

@avl
Copy link

avl commented Jul 23, 2022

I love these methods!

I would love to see *_sub_signed and friends too. I just had a use for saturating_sub_signed (subtracting a signed residual from an unsigned value to create a corrected value). In my case, I can just negate the residual. However, that might cause overflow, in which case the final calculated value would not be correct. This won't really matter in practice, but saturating_sub_signed still would have been nice!

@joshtriplett
Copy link
Member

I just ran into a use case for these as well, in Cargo, for working with CPU counts (e.g. "use all but 1 CPU").

@joshtriplett
Copy link
Member

These have been around for a long time, and it seems like several people are interested in them.

Shall we stabilize these?

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Aug 10, 2022

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Aug 10, 2022
@rfcbot
Copy link

rfcbot commented Aug 12, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Aug 22, 2022
@rfcbot
Copy link

rfcbot commented Aug 22, 2022

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Aug 22, 2022
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Sep 8, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 27, 2022
…s, r=joshtriplett

Stabilize `#![feature(mixed_integer_ops)]`

Tracked and FCP completed in rust-lang#87840.

`@rustbot` label +T-libs-api +S-waiting-on-review +relnotes

r? rust-lang/t-libs-api
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 27, 2022
…s, r=joshtriplett

Stabilize `#![feature(mixed_integer_ops)]`

Tracked and FCP completed in rust-lang#87840.

``@rustbot`` label +T-libs-api +S-waiting-on-review +relnotes

r? rust-lang/t-libs-api
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Sep 27, 2022
…s, r=joshtriplett

Stabilize `#![feature(mixed_integer_ops)]`

Tracked and FCP completed in rust-lang#87840.

```@rustbot``` label +T-libs-api +S-waiting-on-review +relnotes

r? rust-lang/t-libs-api
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 27, 2022
…s, r=joshtriplett

Stabilize `#![feature(mixed_integer_ops)]`

Tracked and FCP completed in rust-lang#87840.

````@rustbot```` label +T-libs-api +S-waiting-on-review +relnotes

r? rust-lang/t-libs-api
@JohnTitor
Copy link
Member

The feature has been stabilized by #101555, closing.

lupont added a commit to lupont/psh that referenced this issue Nov 5, 2022
Previously, we only supported the abbreviation being shorter than its
expansion, e.g. `gs` -> `git status`. Now, the opposite is supported,
e.g. `exa` -> `ls`.

This solution can be enhanced when the feature "mixed_integer_ops" is
released in stable (tracking:
rust-lang/rust#87840).
lupont added a commit to lupont/psh that referenced this issue Nov 5, 2022
Previously, we only supported the abbreviation being shorter than its
expansion, e.g. `gs` -> `git status`. Now, the opposite is supported,
e.g. `exa` -> `ls`.

This solution can be enhanced when the feature "mixed_integer_ops" is
released in stable (tracking:
rust-lang/rust#87840).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants