Closed
Description
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:
- Optional error checking on
+
,-
,*
Implement arithmetic overflow changes #22532 - Implement
wrapping_add
,wrapping_sub
,wrapping_mul
from theWrappingOps
trait Implement arithmetic overflow changes #22532 - Optional error checking on
/
,%
(we currently check unconditionally; see signed division has undefined behaviour on overflow #8460) - Implement
wrapping_div
,wrapping_rem
from theWrappingOps
trait (see arith-oflo: what is semantics of divideint::MIN.wrapped_div(-1)
rfcs#964) Fill in missing parts of Integer overflow API #24420 - Optional error checking on
<<
and>>
overflowing-checking for rhs of shift operators #23536 - Implement
wrapping_lshift
,wrapping_rshift
from theWrappingOps
trait- (renamed to
wrapping_shl
,wrapping_shr
.) Fill in missing parts of Integer overflow API #24420
- (renamed to
- Optional error checking on unary
-
for signed values Check for overflow in arithmetic negation #24500 - Implement
wrapping_neg
from theWrappingOps
trait Fill in missing parts of Integer overflow API #24420 - Lint for use of one of the potentially fallible operations in an
unsafe
fn or fn containingunsafe
blocks- Note that the use need not occur in an
unsafe
block, just a fn containingunsafe
blocks
- Note that the use need not occur in an
- Option to forcibly enable overflow checking
- Overflow checking disabled by default when optimizations are enabled - rustc: Add a debug_assertions #[cfg] directive #22980
- Fix const_eval to do overflow checking based on declared type rather than
u64
/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_X
methods from theWrappingOps
trait- (above two are no longer needed since
as
has been [re]defined to never panic).
- (above two are no longer needed since
- consider saturating cast operations Add a saturating_cast between integers #23596