From df83488f0c2e395e6799ee51c7efd45df1da5a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20G=C3=B6hrs?= Date: Fri, 19 Sep 2025 06:47:53 +0200 Subject: [PATCH] tacd: replace instances of x % N == 0 with x.is_multiple_of(N) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is inspired by a recently added clippy lint: error: manual implementation of `.is_multiple_of()` --> src/dut_power.rs:248:16 | 248 | if N % 2 == 0 { | ^^^^^^^^^^ help: replace with: `N.is_multiple_of(2)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_multiple_of = note: `-D clippy::manual-is-multiple-of` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_is_multiple_of)]` error: manual implementation of `.is_multiple_of()` --> src/ui/screens/diagnostics.rs:256:26 | 256 | let on = self.led_cycle_state % 2 != 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `!self.led_cycle_state.is_multiple_of(2)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_multiple_of Signed-off-by: Leonard Göhrs --- Cargo.toml | 7 ------- src/dut_power.rs | 2 +- src/ui/screens/diagnostics.rs | 2 +- src/ui/screens/locator.rs | 2 +- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 79631310..d6dfe64f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,10 +58,3 @@ lto = true overflow-checks = true opt-level = "z" codegen-units = 1 - -[lints.clippy] -# This is necessary because the `.is_multiple_of()` function that this lint -# suggests is not yet stabilized in the rust version used in Yocto walnascar -# (1.84.1). -# TODO: remove this when updating to a newer yocto release. -manual_is_multiple_of = "allow" diff --git a/src/dut_power.rs b/src/dut_power.rs index 267051d9..7cbefa72 100644 --- a/src/dut_power.rs +++ b/src/dut_power.rs @@ -245,7 +245,7 @@ impl MedianFilter { sorted }; - if N % 2 == 0 { + if N.is_multiple_of(2) { Some((sorted[N / 2 - 1] + sorted[N / 2]) / 2.0) } else { Some(sorted[N / 2]) diff --git a/src/ui/screens/diagnostics.rs b/src/ui/screens/diagnostics.rs index c57b0927..e21b9d7c 100644 --- a/src/ui/screens/diagnostics.rs +++ b/src/ui/screens/diagnostics.rs @@ -253,7 +253,7 @@ impl ActiveScreen for Active { InputEvent::ToggleAction(_) => { self.led_cycle_state = self.led_cycle_state.wrapping_add(1); - let on = self.led_cycle_state % 2 != 0; + let on = !self.led_cycle_state.is_multiple_of(2); let led_brightness = if on { 1.0 } else { 0.0 }; let backlight_brightness = if on { 1.0 } else { 0.1 }; let status_color = match self.led_cycle_state % 8 { diff --git a/src/ui/screens/locator.rs b/src/ui/screens/locator.rs index f064578d..d915f287 100644 --- a/src/ui/screens/locator.rs +++ b/src/ui/screens/locator.rs @@ -120,7 +120,7 @@ impl ActivatableScreen for LocatorScreen { display, Box::new(move |now, target| { // Blink a bar below the hostname at 2Hz - let on = (now.duration_since(start).as_millis() / 500) % 2 == 0; + let on = (now.duration_since(start).as_millis() / 500).is_multiple_of(2); if on { let line = Line::new(Point::new(40, 135), Point::new(200, 135))