checks.rs 649 B

12345678910111213141516171819202122
  1. use std::path::Path;
  2. use anyhow::{anyhow, Result};
  3. use crate::config::Manifest;
  4. /// Check whether `overflow-checks` codegen option is enabled.
  5. ///
  6. /// https://doc.rust-lang.org/rustc/codegen-options/index.html#overflow-checks
  7. pub fn check_overflow(cargo_toml_path: impl AsRef<Path>) -> Result<bool> {
  8. Manifest::from_path(cargo_toml_path)?
  9. .profile
  10. .release
  11. .as_ref()
  12. .and_then(|profile| profile.overflow_checks)
  13. .ok_or(anyhow!(
  14. "`overflow-checks` is not enabled. To enable, add:\n\n\
  15. [profile.release]\n\
  16. overflow-checks = true\n\n\
  17. in workspace root Cargo.toml.",
  18. ))
  19. }