rust-lang / rust-lang/rfcs

Integer overflow RFC needs more wrapper types

Open
#928 4 comments 0 reactions 0 assignees View on GitHub

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.

  1. The RFC documents WrappingOps Wrapping<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.)
  2. 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 a Overflowing<N> trait is warranted.)
  3. We probably also want SaturatingOps and Saturating<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.)
  4. I think we may want some form of support for impl Add<N> for Result<N, Overflow>> where the result type is Result<N, Overflow> (and Overflow is a zero-sized struct). At least, I think this would enable patterns of composition like let value: N = try!(a + b - c + d);
    • ---- (adding more ideas below this line) ----
  5. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.