From 914dba8c6f1c606af017c1e724b1b82d87a8c293 Mon Sep 17 00:00:00 2001 From: Renan Ribeiro <55855728+cosineblast@users.noreply.github.com> Date: Fri, 25 Apr 2025 21:13:43 -0300 Subject: [PATCH] Apply clippy suggestions --- .../nu-command/src/experimental/job_wait.rs | 27 ++++++++----------- crates/nu-protocol/src/engine/jobs.rs | 7 +++-- crates/nu-system/src/util.rs | 1 - 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/crates/nu-command/src/experimental/job_wait.rs b/crates/nu-command/src/experimental/job_wait.rs index 9c83541ea3..251d1ae76e 100644 --- a/crates/nu-command/src/experimental/job_wait.rs +++ b/crates/nu-command/src/experimental/job_wait.rs @@ -55,20 +55,16 @@ Note that this command fails if the provided job id is currently not in the job let mut jobs = engine_state.jobs.lock().expect("jobs lock is poisoned!"); match jobs.lookup_mut(id) { - None => { - return Err(ShellError::JobNotFound { - id: id.get(), - span: head, - }); - } + None => Err(ShellError::JobNotFound { + id: id.get(), + span: head, + }), - Some(Job::Frozen { .. }) => { - return Err(ShellError::UnsupportedJobType { - id: id.get() as usize, - span: head, - kind: "frozen".to_string(), - }); - } + Some(Job::Frozen { .. }) => Err(ShellError::UnsupportedJobType { + id: id.get() as usize, + span: head, + kind: "frozen".to_string(), + }), Some(Job::Thread(job)) => { let waiter = job.on_termination().clone(); @@ -104,9 +100,8 @@ pub fn wait_with_interrupt( loop { interrupted()?; - match wait(check_interval) { - Some(result) => return Ok(result), - None => {} // do nothing, try again + if let Some(result) = wait(check_interval) { + return Ok(result); } } } diff --git a/crates/nu-protocol/src/engine/jobs.rs b/crates/nu-protocol/src/engine/jobs.rs index 32843a1c13..a526555973 100644 --- a/crates/nu-protocol/src/engine/jobs.rs +++ b/crates/nu-protocol/src/engine/jobs.rs @@ -1,7 +1,6 @@ use std::{ collections::{HashMap, HashSet}, - sync::{Arc, Mutex, WaitTimeoutResult}, - time::Instant, + sync::{Arc, Mutex}, }; use nu_system::{kill_by_pid, UnfreezeHandle}; @@ -336,9 +335,9 @@ impl Waiter { { Ok((_guard, result)) => { if result.timed_out() { - return None; + None } else { - return Some(inner.value.get().unwrap()); + Some(inner.value.get().unwrap()) } } Err(_) => panic!("mutex is poisoned!"), diff --git a/crates/nu-system/src/util.rs b/crates/nu-system/src/util.rs index 01663a77c1..73b3575177 100644 --- a/crates/nu-system/src/util.rs +++ b/crates/nu-system/src/util.rs @@ -1,6 +1,5 @@ use std::io; use std::process::Command as CommandSys; -use std::time::{Duration, Instant}; /// Tries to forcefully kill a process by its PID pub fn kill_by_pid(pid: i64) -> io::Result<()> {