RFC: https://github.com/rust-lang/rfcs/pull/560 Final text: https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md List of tasks to accomplish: - [x] Optional error checking on `+`, `-`, `*` #22532 - [x] Implement `wrapping_add`, `wrapping_sub`, `wrapping_mul` from the `WrappingOps` trait #22532 - [x] Optional error checking on `/`, `%` (we currently check unconditionally; see #8460) - [x] Implement `wrapping_div`, `wrapping_rem` from the `WrappingOps` trait (see https://github.com/rust-lang/rfcs/issues/964) #24420 - [x] Optional error checking on `<<` and `>>` #23536 - [x] Implement `wrapping_lshift`, `wrapping_rshift` from the `WrappingOps` trait - (renamed to `wrapping_shl`, `wrapping_shr`.) #24420 - [x] Optional error checking on unary `-` for signed values #24500 - [x] Implement `wrapping_neg` from the `WrappingOps` trait #24420 - [ ] Lint for use of one of the potentially fallible operations in an `unsafe` fn or fn containing `unsafe` blocks - Note that the use need not occur _in_ an `unsafe` block, just a fn containing `unsafe` blocks - [x] Option to forcibly enable overflow checking - [x] Overflow checking disabled by default when optimizations are enabled - #22980 - [x] Fix const_eval to do overflow checking based on declared type rather than `u64`/`i64` (on all of the above cases) - #23863 (#22531) --- - [ ] ~~Optional error checking on `as` (see http://internals.rust-lang.org/t/on-casts-and-checked-overflow/1710/15)~~ - [ ] ~~Implement `wrapping_as_X` methods from the `WrappingOps` trait~~ - (above two are no longer needed since `as` has been [re]defined to never panic). - [ ] consider saturating cast operations https://github.com/rust-lang/rust/issues/23596
RFC: rust-lang/rfcs#560
Final text: https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md
List of tasks to accomplish:
+,-,*Implement arithmetic overflow changes #22532wrapping_add,wrapping_sub,wrapping_mulfrom theWrappingOpstrait Implement arithmetic overflow changes #22532/,%(we currently check unconditionally; see signed division has undefined behaviour on overflow #8460)wrapping_div,wrapping_remfrom theWrappingOpstrait (see arith-oflo: what is semantics of divideint::MIN.wrapped_div(-1)rfcs#964) Fill in missing parts of Integer overflow API #24420<<and>>overflowing-checking for rhs of shift operators #23536wrapping_lshift,wrapping_rshiftfrom theWrappingOpstraitwrapping_shl,wrapping_shr.) Fill in missing parts of Integer overflow API #24420-for signed values Check for overflow in arithmetic negation #24500wrapping_negfrom theWrappingOpstrait Fill in missing parts of Integer overflow API #24420unsafefn or fn containingunsafeblocksunsafeblock, just a fn containingunsafeblocksu64/i64(on all of the above cases) - arithmetic-overflow checks during const-eval #23863 (constant evaluation should not mask overflow for cases that are otherwise checked #22531)Optional error checking onas(see http://internals.rust-lang.org/t/on-casts-and-checked-overflow/1710/15)Implementwrapping_as_Xmethods from theWrappingOpstraitashas been [re]defined to never panic).