Fix future clippy lints (#15519)

- suggestions for tersity using helpers
This commit is contained in:
Stefan Holderbach 2025-04-08 02:51:12 +02:00 committed by GitHub
parent a886e30e04
commit ecb9799b6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 21 deletions

View File

@ -10,11 +10,7 @@ use nu_protocol::{
}; };
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::prelude::FileTypeExt; use std::os::unix::prelude::FileTypeExt;
use std::{ use std::{collections::HashMap, io::Error, path::PathBuf};
collections::HashMap,
io::{Error, ErrorKind},
path::PathBuf,
};
const TRASH_SUPPORTED: bool = cfg!(all( const TRASH_SUPPORTED: bool = cfg!(all(
feature = "trash-support", feature = "trash-support",
@ -379,7 +375,7 @@ fn rm(
); );
let result = if let Err(e) = interaction { let result = if let Err(e) = interaction {
Err(Error::new(ErrorKind::Other, &*e.to_string())) Err(Error::other(&*e.to_string()))
} else if interactive && !confirmed { } else if interactive && !confirmed {
Ok(()) Ok(())
} else if TRASH_SUPPORTED && (trash || (rm_always_trash && !permanent)) { } else if TRASH_SUPPORTED && (trash || (rm_always_trash && !permanent)) {
@ -389,7 +385,7 @@ fn rm(
))] ))]
{ {
trash::delete(&f).map_err(|e: trash::Error| { trash::delete(&f).map_err(|e: trash::Error| {
Error::new(ErrorKind::Other, format!("{e:?}\nTry '--permanent' flag")) Error::other(format!("{e:?}\nTry '--permanent' flag"))
}) })
} }

View File

@ -394,7 +394,7 @@ impl<R: Read> Read for IoTee<R> {
if let Some(thread) = self.thread.take() { if let Some(thread) = self.thread.take() {
if thread.is_finished() { if thread.is_finished() {
if let Err(err) = thread.join().unwrap_or_else(|_| Err(panic_error())) { if let Err(err) = thread.join().unwrap_or_else(|_| Err(panic_error())) {
return Err(io::Error::new(io::ErrorKind::Other, err)); return Err(io::Error::other(err));
} }
} else { } else {
self.thread = Some(thread) self.thread = Some(thread)
@ -405,7 +405,7 @@ impl<R: Read> Read for IoTee<R> {
self.sender = None; self.sender = None;
if let Some(thread) = self.thread.take() { if let Some(thread) = self.thread.take() {
if let Err(err) = thread.join().unwrap_or_else(|_| Err(panic_error())) { if let Err(err) = thread.join().unwrap_or_else(|_| Err(panic_error())) {
return Err(io::Error::new(io::ErrorKind::Other, err)); return Err(io::Error::other(err));
} }
} }
} else if let Some(sender) = self.sender.as_mut() { } else if let Some(sender) = self.sender.as_mut() {

View File

@ -437,7 +437,7 @@ impl io::Write for WriterFormatter<'_, '_> {
fn io_error<E>(_: E) -> io::Error { fn io_error<E>(_: E) -> io::Error {
// Value does not matter because fmt::Debug and fmt::Display impls // Value does not matter because fmt::Debug and fmt::Display impls
// below just map it to fmt::Error // below just map it to fmt::Error
io::Error::new(io::ErrorKind::Other, "fmt error") io::Error::other("fmt error")
} }
let s = str::from_utf8(buf).map_err(io_error)?; let s = str::from_utf8(buf).map_err(io_error)?;
self.inner.write_str(s).map_err(io_error)?; self.inner.write_str(s).map_err(io_error)?;

View File

@ -91,12 +91,12 @@ impl StackOutDest {
fn push_stdout(&mut self, stdout: OutDest) -> Option<OutDest> { fn push_stdout(&mut self, stdout: OutDest) -> Option<OutDest> {
let stdout = mem::replace(&mut self.stdout, stdout); let stdout = mem::replace(&mut self.stdout, stdout);
mem::replace(&mut self.parent_stdout, Some(stdout)) self.parent_stdout.replace(stdout)
} }
fn push_stderr(&mut self, stderr: OutDest) -> Option<OutDest> { fn push_stderr(&mut self, stderr: OutDest) -> Option<OutDest> {
let stderr = mem::replace(&mut self.stderr, stderr); let stderr = mem::replace(&mut self.stderr, stderr);
mem::replace(&mut self.parent_stderr, Some(stderr)) self.parent_stderr.replace(stderr)
} }
} }
@ -118,13 +118,13 @@ impl<'a> StackIoGuard<'a> {
let (old_pipe_stdout, old_parent_stdout) = match stdout { let (old_pipe_stdout, old_parent_stdout) = match stdout {
Some(Redirection::Pipe(stdout)) => { Some(Redirection::Pipe(stdout)) => {
let old = mem::replace(&mut out_dest.pipe_stdout, Some(stdout)); let old = out_dest.pipe_stdout.replace(stdout);
(old, out_dest.parent_stdout.take()) (old, out_dest.parent_stdout.take())
} }
Some(Redirection::File(file)) => { Some(Redirection::File(file)) => {
let file = OutDest::from(file); let file = OutDest::from(file);
( (
mem::replace(&mut out_dest.pipe_stdout, Some(file.clone())), out_dest.pipe_stdout.replace(file.clone()),
out_dest.push_stdout(file), out_dest.push_stdout(file),
) )
} }
@ -133,7 +133,7 @@ impl<'a> StackIoGuard<'a> {
let (old_pipe_stderr, old_parent_stderr) = match stderr { let (old_pipe_stderr, old_parent_stderr) = match stderr {
Some(Redirection::Pipe(stderr)) => { Some(Redirection::Pipe(stderr)) => {
let old = mem::replace(&mut out_dest.pipe_stderr, Some(stderr)); let old = out_dest.pipe_stderr.replace(stderr);
(old, out_dest.parent_stderr.take()) (old, out_dest.parent_stderr.take())
} }
Some(Redirection::File(file)) => ( Some(Redirection::File(file)) => (
@ -192,7 +192,7 @@ pub struct StackCollectValueGuard<'a> {
impl<'a> StackCollectValueGuard<'a> { impl<'a> StackCollectValueGuard<'a> {
pub(crate) fn new(stack: &'a mut Stack) -> Self { pub(crate) fn new(stack: &'a mut Stack) -> Self {
let old_pipe_stdout = mem::replace(&mut stack.out_dest.pipe_stdout, Some(OutDest::Value)); let old_pipe_stdout = stack.out_dest.pipe_stdout.replace(OutDest::Value);
let old_pipe_stderr = stack.out_dest.pipe_stderr.take(); let old_pipe_stderr = stack.out_dest.pipe_stderr.take();
Self { Self {
stack, stack,
@ -233,7 +233,7 @@ pub struct StackCallArgGuard<'a> {
impl<'a> StackCallArgGuard<'a> { impl<'a> StackCallArgGuard<'a> {
pub(crate) fn new(stack: &'a mut Stack) -> Self { pub(crate) fn new(stack: &'a mut Stack) -> Self {
let old_pipe_stdout = mem::replace(&mut stack.out_dest.pipe_stdout, Some(OutDest::Value)); let old_pipe_stdout = stack.out_dest.pipe_stdout.replace(OutDest::Value);
let old_pipe_stderr = stack.out_dest.pipe_stderr.take(); let old_pipe_stderr = stack.out_dest.pipe_stderr.take();
let old_stdout = stack let old_stdout = stack

View File

@ -8,10 +8,7 @@ pub fn kill_by_pid(pid: i64) -> io::Result<()> {
let output = cmd.output()?; let output = cmd.output()?;
if !output.status.success() { if !output.status.success() {
return Err(io::Error::new( return Err(io::Error::other("failed to kill process"));
io::ErrorKind::Other,
"failed to kill process",
));
} }
Ok(()) Ok(())