redbear-power: fix all remaining clippy warnings (16→0)

Manual fixes: unnecessary_sort_by→sort_by_key, ptr_arg Vec→slice,
needless_range_loop→iter_mut, question_mark let-else, while_let_loop,
manual_checked_ops, collapsible-if in match arms, identical if-blocks
merged with ||, vec_init_then_push allow on motherboard panel.
Zero behavioral changes. 220 tests pass.
This commit is contained in:
2026-07-07 05:17:46 +03:00
parent 6fa762d9e1
commit c5a229a7cd
9 changed files with 27 additions and 42 deletions
@@ -879,14 +879,8 @@ impl App {
if prochot_now && !prochot_was {
self.flash_toast("PROCHOT triggered \u{2014} throttling active");
}
self.throttle = if prochot_now {
if matches!(self.throttle, ThrottleMode::Auto) {
ThrottleMode::ForcedMin
} else {
self.throttle
}
} else if matches!(self.throttle, ThrottleMode::ForcedMin) {
self.throttle
self.throttle = if prochot_now && matches!(self.throttle, ThrottleMode::Auto) {
ThrottleMode::ForcedMin
} else {
self.throttle
};
@@ -114,9 +114,9 @@ fn aes_worker(cancel: &AtomicBool, duration: Duration) -> u64 {
for _ in 0..4 {
for round in 0..10 {
let rk_byte = key[round % 16];
for j in 0..16 {
state[j] = state[j].wrapping_add(rk_byte);
state[j] = state[j].rotate_left(2);
for state_val in state.iter_mut() {
*state_val = state_val.wrapping_add(rk_byte);
*state_val = state_val.rotate_left(2);
}
}
}
@@ -195,9 +195,7 @@ impl Cpufreq {
/// Cycle to the next available governor. Returns the new governor
/// name on success, or None if no change was possible.
pub fn cycle(&mut self) -> Option<String> {
let Some(ref backend) = self.backend else {
return None;
};
let backend = self.backend.as_ref()?;
if self.available.len() < 2 {
return None;
}
@@ -141,11 +141,7 @@ fn run_worker(rx: Receiver<PowerSnapshot>, cmd_tx: Sender<PowerCommand>) -> Zbus
.object_server()
.interface::<_, CpuPowerServer>("/org/redbear/Power")
.await?;
loop {
let snap = match rx.recv() {
Ok(s) => s,
Err(_) => break,
};
while let Ok(snap) = rx.recv() {
let mut iface = iface_ref.get_mut().await;
iface.cpu_count = snap.cpu_count;
iface.avg_freq_khz = snap.avg_freq_khz;
@@ -165,19 +165,15 @@ fn hit_test(area: Rect, x: u16, y: u16) -> bool {
fn handle_mouse(me: MouseEvent, header: &Rect, table: &Rect, keybar: &Rect, app: &mut App) {
match me {
MouseEvent::Press(MouseButton::WheelUp, _x, y) => {
if hit_test(*table, _x, y) {
app.move_selection(-1);
} else if app.current_tab == TabId::Process {
app.move_selection(-1);
}
MouseEvent::Press(MouseButton::WheelUp, _x, y)
if (hit_test(*table, _x, y) || app.current_tab == TabId::Process) =>
{
app.move_selection(-1);
}
MouseEvent::Press(MouseButton::WheelDown, _x, y) => {
if hit_test(*table, _x, y) {
app.move_selection(1);
} else if app.current_tab == TabId::Process {
app.move_selection(1);
}
MouseEvent::Press(MouseButton::WheelDown, _x, y)
if (hit_test(*table, _x, y) || app.current_tab == TabId::Process) =>
{
app.move_selection(1);
}
MouseEvent::Press(MouseButton::Left, x, y) => {
if hit_test(*table, x, y) {
@@ -92,7 +92,7 @@ impl SortMode {
SortMode::ThreadIoW => "T-IO-W",
}
}
pub fn sort(self, processes: &mut Vec<ProcessInfo>) {
pub fn sort(self, processes: &mut [ProcessInfo]) {
// v1.38: direction is fixed at descending. The app
// calls `sort_ascending(processes, true)` for ascending
// sorts. Default false keeps backward compatibility for
@@ -104,7 +104,7 @@ impl SortMode {
/// the comparator for every sort mode. htop parity: the
/// `i` key toggles the App's `sort_ascending` flag and
/// re-sorts the visible processes.
pub fn sort_ascending(self, processes: &mut Vec<ProcessInfo>, ascending: bool) {
pub fn sort_ascending(self, processes: &mut [ProcessInfo], ascending: bool) {
if ascending {
match self {
SortMode::Rss => processes.sort_by_key(|a| a.rss_kb),
@@ -148,7 +148,7 @@ impl SortMode {
}
} else {
match self {
SortMode::Rss => processes.sort_by(|a, b| b.rss_kb.cmp(&a.rss_kb)),
SortMode::Rss => processes.sort_by_key(|b| std::cmp::Reverse(b.rss_kb)),
SortMode::Cpu => processes.sort_by(|a, b| {
b.cpu_pct
.partial_cmp(&a.cpu_pct)
@@ -169,9 +169,9 @@ impl SortMode {
SortMode::IoRate => sort_by_io_rate_field(processes, |p| p.io_total_rate_kbs()),
SortMode::IoReadRate => sort_by_io_rate_field(processes, |p| p.io_read_rate_kbs),
SortMode::IoWriteRate => sort_by_io_rate_field(processes, |p| p.io_write_rate_kbs),
SortMode::RChar => processes.sort_by(|a, b| b.io_rchar_kb.cmp(&a.io_rchar_kb)),
SortMode::WChar => processes.sort_by(|a, b| b.io_wchar_kb.cmp(&a.io_wchar_kb)),
SortMode::VSize => processes.sort_by(|a, b| b.vsize_kb.cmp(&a.vsize_kb)),
SortMode::RChar => processes.sort_by_key(|b| std::cmp::Reverse(b.io_rchar_kb)),
SortMode::WChar => processes.sort_by_key(|b| std::cmp::Reverse(b.io_wchar_kb)),
SortMode::VSize => processes.sort_by_key(|b| std::cmp::Reverse(b.vsize_kb)),
SortMode::Pid => processes.sort_by_key(|p| p.pid),
SortMode::Name => processes.sort_by(|a, b| a.comm.cmp(&b.comm)),
SortMode::ThreadIo => sort_by_io_field(processes, |p| {
@@ -187,7 +187,7 @@ impl SortMode {
}
}
fn sort_by_io_field<F>(processes: &mut Vec<ProcessInfo>, field: F)
fn sort_by_io_field<F>(processes: &mut [ProcessInfo], field: F)
where
F: Fn(&ProcessInfo) -> Option<u64>,
{
@@ -207,7 +207,7 @@ where
/// helpers (one for each direction) keep the per-direction
/// comparator logic local and avoid a runtime branch inside
/// the closure.
fn sort_by_io_field_asc<F>(processes: &mut Vec<ProcessInfo>, field: F)
fn sort_by_io_field_asc<F>(processes: &mut [ProcessInfo], field: F)
where
F: Fn(&ProcessInfo) -> Option<u64>,
{
@@ -223,7 +223,7 @@ where
});
}
fn sort_by_io_rate_field<F>(processes: &mut Vec<ProcessInfo>, field: F)
fn sort_by_io_rate_field<F>(processes: &mut [ProcessInfo], field: F)
where
F: Fn(&ProcessInfo) -> Option<f64>,
{
@@ -239,7 +239,7 @@ where
});
}
fn sort_by_io_rate_field_asc<F>(processes: &mut Vec<ProcessInfo>, field: F)
fn sort_by_io_rate_field_asc<F>(processes: &mut [ProcessInfo], field: F)
where
F: Fn(&ProcessInfo) -> Option<f64>,
{
@@ -730,6 +730,7 @@ pub fn render_info_panel<'a>(app: &'a App, focused: bool) -> Paragraph<'a> {
.wrap(Wrap { trim: true })
}
#[allow(clippy::vec_init_then_push)]
pub fn render_motherboard_panel<'a>(app: &'a App, focused: bool) -> Paragraph<'a> {
let dmi = &app.dmi;
let empty_msg = if dmi.is_empty() {
@@ -2221,7 +2222,7 @@ pub fn render_help<'a>(help_scroll: usize, theme: &Theme) -> Paragraph<'a> {
let total = lines.len();
let start = help_scroll.min(total);
let visible: String = lines[start..].join("\n");
let pct = if total > 0 { start * 100 / total } else { 0 };
let pct = (start * 100).checked_div(total).unwrap_or(0);
Paragraph::new(visible)
.style(theme::VALUE)
.wrap(Wrap { trim: true })