From 642eff9e1f970b8491afb978b8e1d6ddd2d680cf Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sun, 17 Nov 2024 12:29:54 -0800 Subject: [PATCH] Fix some clippies and remove some dead code --- src/builtins/fg.rs | 5 ++--- src/event.rs | 4 ++-- src/proc.rs | 20 +++++--------------- src/wutil/dir_iter.rs | 2 +- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/builtins/fg.rs b/src/builtins/fg.rs index 26ffe1738..675a06ebd 100644 --- a/src/builtins/fg.rs +++ b/src/builtins/fg.rs @@ -52,9 +52,8 @@ pub fn fg(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> Optio // try to locate the job $argv[1], since we need to determine which error message to // emit (ambigous job specification vs malformed job id). let mut found_job = false; - match fish_wcstoi(argv[optind]).map(Pid::new) { - Ok(Some(pid)) => found_job = parser.job_get_from_pid(pid).is_some(), - _ => (), + if let Ok(Some(pid)) = fish_wcstoi(argv[optind]).map(Pid::new) { + found_job = parser.job_get_from_pid(pid).is_some(); }; if found_job { diff --git a/src/event.rs b/src/event.rs index 77fc30139..2ae9ee8cc 100644 --- a/src/event.rs +++ b/src/event.rs @@ -380,7 +380,7 @@ pub fn get_desc(parser: &Parser, evt: &Event) -> WString { format!("signal handler for {} ({})", signal.name(), signal.desc(),) } EventDescription::Variable { name } => format!("handler for variable '{name}'"), - EventDescription::ProcessExit { pid: None } => format!("exit handler for any process"), + EventDescription::ProcessExit { pid: None } => "exit handler for any process".to_string(), EventDescription::ProcessExit { pid: Some(pid) } => { format!("exit handler for process {pid}") } @@ -392,7 +392,7 @@ pub fn get_desc(parser: &Parser, evt: &Event) -> WString { format!("exit handler for job with pid {pid}") } } else { - format!("exit handler for any job") + "exit handler for any job".to_string() } } EventDescription::CallerExit { .. } => { diff --git a/src/proc.rs b/src/proc.rs index 91f29e370..cc8012183 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -517,13 +517,10 @@ pub struct Pid(NonZeroU32); impl Pid { #[inline(always)] - pub fn new>(pid: P) -> Option { - let pid = pid.into(); - assert!(pid >= 0, "Invalid negative PID value!"); - match NonZeroU32::new(pid as u32) { - Some(x) => Some(Pid(x)), - None => None, - } + pub fn new(pid: i32) -> Option { + // Construct a pid from an i32, which must be at least zero. + assert!(pid >= 0, "Pid must be at least zero"); + NonZeroU32::new(pid as u32).map(Pid) } #[inline(always)] pub fn get(&self) -> i32 { @@ -536,13 +533,6 @@ impl Pid { } } -impl Into for u32 { - #[inline(always)] - fn into(self) -> Pid { - Pid::new(self as i32).unwrap() - } -} - impl std::fmt::Display for Pid { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(&self.get(), f) @@ -557,7 +547,7 @@ impl ToWString for Pid { impl fish_printf::ToArg<'static> for Pid { fn to_arg(self) -> fish_printf::Arg<'static> { - fish_printf::Arg::UInt(self.get() as u64) + self.get().to_arg() } } diff --git a/src/wutil/dir_iter.rs b/src/wutil/dir_iter.rs index 88f140637..3b4f7be4e 100644 --- a/src/wutil/dir_iter.rs +++ b/src/wutil/dir_iter.rs @@ -277,7 +277,7 @@ impl DirIter { } self.entry.reset(); - self.entry.name = cstr2wcstring(&d_name); + self.entry.name = cstr2wcstring(d_name); #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] { self.entry.inode = dent.d_fileno;