On Thu, Feb 19, 2026 at 01:54:09PM -0500, John Snow wrote:
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 <[email protected]>
---
rust/hw/core/src/qdev.rs | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/rust/hw/core/src/qdev.rs b/rust/hw/core/src/qdev.rs
index 145e20a984f..b2e5441079d 100644
--- a/rust/hw/core/src/qdev.rs
+++ b/rust/hw/core/src/qdev.rs
@@ -425,18 +425,16 @@ pub const fn period_from_ns(ns: u64) -> u64 {
    }

    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,

This looks like unwrap_or_default:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&code=fn%20main()%20%7B%0A%20%20let%20asdf%20%3D%20100u64%3B%0A%0A%20%20println!(%22%7B%3A%23%3F%7D%22%2C%20asdf.checked_div(5).unwrap_or_default())%3B%0A%20%20println!(%22%7B%3A%23%3F%7D%22%2C%20asdf.checked_div(0).unwrap_or_default())%3B%0A%7D%0A

in case you want to make it shorter O:-)

        }
    }

--
2.53.0


Attachment: signature.asc
Description: PGP signature

Reply via email to