Hacker News new | ask | show | jobs
by westicecoast32 2199 days ago
Really? I find that rust is worse than C++ thanks to clang

For example, is there a way in rust to get a runtime error when there's an int overflow?

2 comments

Of course. rustc has the "-C overflow-checks" flag. Cargo turns it on by default for debug builds. To turn it on for release builds, just put "overflow-checks = true" in the [profile.release] section of your Cargo.toml.

Or better yet, the Rust standard library exposes all the relevant LLVM intrinsics for the primitives, so you have the {Integer}::checked_, {Integer}::saturating_, {Integer}::wrapping_, {Integer}::overflowing_ (inlined) functions to do all your integer math in an error-free fashion.

Yes there is. Overflow panics by default in debug mode, and you can turn that in in release mode with the overflow-checks compiler option. There's also checked_add.