How to compile and run an optimized Rust program with overflow checking enabled

I am writing a program that calculates quite a lot, and it annoyingly slowly starts in debug mode.

My program also suffers integer overflows because I am reading data from u8 and u8 to unexpected places using type inference, and Rust prefers overflow rather than moving integers to larger types.

In release mode, disables the overflow check:

 cargo run --release 

How can I create a Rust executable with optimizations and runtime overflow checks?

+5
source share
1 answer

The easiest one can be in test mode or dev with optimization :

 [profile.dev] opt-level = 3 

Alternatively, you can compile in release mode with debug statements enabled:

 [profile.release] debug-assertions = true 
+7
source

Source: https://habr.com/ru/post/1237289/


All Articles