且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在启用溢出检查的情况下编译和运行优化的Rust程序

更新时间:2022-11-03 14:42:45

您可以在发布模式下进行编译启用了溢出检查

You can compile in release mode with overflow checks enabled:

[profile.release]
overflow-checks = true

这会将 -Coverflow-checks = true 传递给编译器。在早期版本的Rust中,溢出检查 debug-assertions 开关的一部分,因此您可能需要使用

This passes -C overflow-checks=true to the compiler. In earlier versions of Rust, overflow-checks was part of the debug-assertions switch, so you may need to use that in certain cases.

其他时候,最简单的方法可能是构建在测试或开发人员模式下进行优化

Other times, the easiest thing might be to build in test or dev mode with optimizations:

[profile.dev]
opt-level = 3