Comment by PoignardAzur

3 years ago

The promise of Rust is that you never run into undefined behavior if you only use safe code. There are some caveats (using dependencies with badly written unsafe code, the noalias bugs others mentioned) but in the general case, if you're writing code without 'unsafe' blocks, you're not going to trigger UB.

You're certainly not going to run into LLVM optimizing your bound-check out of existence because it occurs after an overflowing operation.