diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ace0baf9bd..0d24eb84e1 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -46,6 +46,7 @@ redundant_explicit_links = "deny" [workspace.lints.clippy] # default-warn lints result_unit_err = "allow" +manual_checked_ops = "deny" should_implement_trait = "deny" # can be for a reason, e.g. in callbacks unused_self = "allow" diff --git a/rust/hw/core/src/qdev.rs b/rust/hw/core/src/qdev.rs index 145e20a984..b2e5441079 100644 --- a/rust/hw/core/src/qdev.rs +++ b/rust/hw/core/src/qdev.rs @@ -425,18 +425,16 @@ impl Clock { } pub const fn period_from_hz(hz: u64) -> u64 { - if hz == 0 { - 0 - } else { - Self::PERIOD_1SEC / hz + match Self::PERIOD_1SEC.checked_div(hz) { + Some(value) => value, + None => 0, } } pub const fn period_to_hz(period: u64) -> u64 { - if period == 0 { - 0 - } else { - Self::PERIOD_1SEC / period + match Self::PERIOD_1SEC.checked_div(period) { + Some(value) => value, + None => 0, } }