Runtime Guarantees
No undefined behavior at runtime:
- Array access is bounds checked.
- Integer overflow is defined.
Key points:
-
Integer overflow is defined via a compile-time flag. The options are either a panic (a controlled crash of the program) or wrap-around semantics. By default, you get panics in debug mode (
cargo build) and wrap-around in release mode (cargo build --release). -
Bounds checking cannot be disabled with a compiler flag. It can also not be disabled directly with the
unsafekeyword. However,unsafeallows you to call functions such asslice::get_uncheckedwhich does not do bounds checking.