rust: use checked_div to make clippy happy
When upgrading from Fedora 41 to Fedora 43 for CI tests, clippy begins complaining about not using checked_div instead of manually checking divisors. Make clippy happy and use checked_div() instead. Signed-off-by: John Snow <jsnow@redhat.com> Link: https://lore.kernel.org/r/20260219185409.708130-2-jsnow@redhat.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
@@ -46,6 +46,7 @@ redundant_explicit_links = "deny"
|
|||||||
[workspace.lints.clippy]
|
[workspace.lints.clippy]
|
||||||
# default-warn lints
|
# default-warn lints
|
||||||
result_unit_err = "allow"
|
result_unit_err = "allow"
|
||||||
|
manual_checked_ops = "deny"
|
||||||
should_implement_trait = "deny"
|
should_implement_trait = "deny"
|
||||||
# can be for a reason, e.g. in callbacks
|
# can be for a reason, e.g. in callbacks
|
||||||
unused_self = "allow"
|
unused_self = "allow"
|
||||||
|
|||||||
@@ -425,18 +425,16 @@ pub const fn period_from_ns(ns: u64) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const fn period_from_hz(hz: u64) -> u64 {
|
pub const fn period_from_hz(hz: u64) -> u64 {
|
||||||
if hz == 0 {
|
match Self::PERIOD_1SEC.checked_div(hz) {
|
||||||
0
|
Some(value) => value,
|
||||||
} else {
|
None => 0,
|
||||||
Self::PERIOD_1SEC / hz
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn period_to_hz(period: u64) -> u64 {
|
pub const fn period_to_hz(period: u64) -> u64 {
|
||||||
if period == 0 {
|
match Self::PERIOD_1SEC.checked_div(period) {
|
||||||
0
|
Some(value) => value,
|
||||||
} else {
|
None => 0,
|
||||||
Self::PERIOD_1SEC / period
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user