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>
John Snow committed
Feb 19, 2026 at 13:54 UTC
062acfffe5c07940ec0c419d7e353b46c0514c92
2 files changed
+7
-8
rust/Cargo.toml
+1
@@ -46,6 +46,7 @@ redundant_explicit_links = "deny"
46
[workspace.lints.clippy]
47
# default-warn lints
48
result_unit_err = "allow"
49
+manual_checked_ops = "deny"
50
should_implement_trait = "deny"
51
# can be for a reason, e.g. in callbacks
52
unused_self = "allow"
rust/hw/core/src/qdev.rs
+6
-8
@@ -425,18 +425,16 @@ impl Clock {
425
}
426
427
pub const fn period_from_hz(hz: u64) -> u64 {
428
- if hz == 0 {
429
- 0
430
- } else {
431
- Self::PERIOD_1SEC / hz
428
+ match Self::PERIOD_1SEC.checked_div(hz) {
429
+ Some(value) => value,
430
+ None => 0,
431
}
432
}
433
434
pub const fn period_to_hz(period: u64) -> u64 {
436
- if period == 0 {
437
- 0
438
- } else {
439
- Self::PERIOD_1SEC / period
435
+ match Self::PERIOD_1SEC.checked_div(period) {
436
+ Some(value) => value,
437
+ None => 0,
438
}
439
}
440