Integer overflow RFC needs more wrapper types
Open
Nobody has claimed this yet.
T-libs
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
This is an issue in need of a PR to modify RFC #560 (text)
During the course of my work attempting to land the integer overflow checking PRs (see https://github.com/rust-lang/rust/pull/22532), I identified some simple types that we should consider adding to the stdlib.
- The RFC documents
WrappingOpsWrapping<N>, which just marks the type as following the usual arithmetic modulo bitwidth rules. (So this is sort of built-in already, not a new change.) - In addition, I added
OverflowingOps, which provides methods for e.g.overflowing_add(self, Self) -> (Self, bool), where the returned boolean is a flag indicating whether overflow occurred. This was quite useful for composing certain functions where knowledge of overflow was needed. (i am not sure if aOverflowing<N>trait is warranted.) - We probably also want
SaturatingOpsandSaturating<N>. (I think we already have the methods for the former; so that is just a question of whether the ops need their its own trait. But I think `Saturating is justified either way.) - I think we may want some form of support for
impl Add<N> for Result<N, Overflow>>where the result type isResult<N, Overflow>(andOverflowis a zero-sized struct). At least, I think this would enable patterns of composition likelet value: N = try!(a + b - c + d);- ---- (adding more ideas below this line) ----
- Atomic numeric types probably need to be addressed in some way as well; see discussion here: https://github.com/rust-lang/rust/pull/20795#issuecomment-73876689
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with RFC #560 and the integer-overflow PRs and discussion linked in the issue. Determine which wrapper types, traits, Result arithmetic, and atomic numeric concerns belong in the proposal, then update the RFC with an agreed scope and design.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100