rust: use checked_div()
cover rust: use checked_div()
When upgrading from Fedora 41 to Fedora 43 for our CI tests, (Which I do in
https://patchew.org/QEMU/[email protected]/),
clippy begins complaining about not using checked_div instead of manually checking divisors; see https://gitlab.com/jsnow/qemu/-/jobs/13169193931
This patch aims to make Clippy happy and prevent any regressions caused by the lcitool refresh.
(Tested only via GitLab CI, and I am not exactly a rust wizard...)
John Snow (1):
rust: use checked_div to make clippy happy
rust/hw/core/src/qdev.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/1 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.
--- rust/hw/core/src/qdev.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
rust/hw/core/src/qdev.rs +6 -8
@@ -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 period.checked_div (Self ::PERIOD_1SEC ) { +Some (value) => value, +None =>0 , } }
Signature · 1 line
2.53.0
Re: [PATCH 1/1] rust: use checked_div to make clippy happy
Quoted 7 lines · John Snow
When upgrading from Fedora 41 to Fedora 43 for CI tests, clippy begins complaining about not using
checked_divinstead of manually checking divisors. Make clippy happy and usechecked_div()instead.Signed-off-by John Snow <[email protected]>---
Quoted 35 lines
rust/hw/core/src/qdev.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)rust/hw/core/src/qdev.rs +6
-9@@ -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 period.checked_div (Self ::PERIOD_1SEC ) { +Some (value) => value, +None =>0 , } } --2.53.0
Re: [PATCH 1/1] rust: use checked_div to make clippy happy
In reply to John SnowQuoted 28 lines · John Snow
When upgrading from Fedora 41 to Fedora 43 for CI tests, clippy begins complaining about not using
checked_divinstead of manually checking divisors. Make clippy happy and usechecked_div()instead.Signed-off-by John Snow <[email protected]>--- rust/hw/core/src/qdev.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)rust/hw/core/src/qdev.rs +3
-4@@ -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 {
rust/hw/core/src/qdev.rs pub const fn period_from_ns(ns: u64) -> u64 { · line 440
Quoted 10 lines
rust/hw/core/src/qdev.rs +3
-4-if period ==0 { -0 - }else { -Self ::PERIOD_1SEC / period +match period.checked_div (Self ::PERIOD_1SEC ) { +Some (value) => value, +None =>0 , } }
These conversions are inconsistent about the placement of divisor and dividend.
r~
Re: [PATCH 1/1] rust: use checked_div to make clippy happy
Quoted 43 lines · Richard Henderson
Quoted 28 lines · John Snow
When upgrading from Fedora 41 to Fedora 43 for CI tests, clippy begins complaining about not using
checked_divinstead of manually checking divisors. Make clippy happy and usechecked_div()instead.Signed-off-by John Snow <[email protected]>--- rust/hw/core/src/qdev.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)rust/hw/core/src/qdev.rs +3
-4@@ -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 {rust/hw/core/src/qdev.rs pub const fn period_from_ns(ns: u64) -> u64 { · line 440
Quoted 10 lines
rust/hw/core/src/qdev.rs +3
-4-if period ==0 { -0 - }else { -Self ::PERIOD_1SEC / period +match period.checked_div (Self ::PERIOD_1SEC ) { +Some (value) => value, +None =>0 , } }These conversions are inconsistent about the placement of divisor and dividend.
Quoted 2 lines
r~
Whoops, fugue state. I'll fix.