The Rust Reference is underspecified about how overflow would behave in release mode
⚓ Rust 📅 2025-09-19 👤 surdeus 👁️ 9fn main() {
let i = i32::MAX +1;
}
expr.operator.int-overflow only talks about how the behavior is under the debug mode
Integer operators will panic when they overflow when compiled in debug mode. The
-C debug-assertionsand-C overflow-checkscompiler flags can be used to control this more directly. The following things are considered to be overflow:
- When
+,*or binary-create a value greater than the maximum value, or less than the minimum value that can be stored.- Applying unary
-to the most negative value of any signed integer type, unless the operand is a literal expression (or a literal expression standing alone inside one or more grouped expressions).- Using
/or%, where the left-hand argument is the smallest integer of a signed integer type and the right-hand argument is-1. These checks occur even when-C overflow-checksis disabled, for legacy reasons.- Using << or >> where the right-hand argument is greater than or equal to the number of bits in the type of the left-hand argument, or is negative.
It says nothing about how the behavior would be in the release mode. Where can I find the associated documents other than the book?
2 posts - 2 participants
🏷️ Rust_feed