Skip to content

Commit ecb9799

Browse files
authored
Fix future clippy lints (nushell#15519)
- suggestions for tersity using helpers
1 parent a886e30 commit ecb9799

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

crates/nu-command/src/filesystem/rm.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ use nu_protocol::{
1010
};
1111
#[cfg(unix)]
1212
use std::os::unix::prelude::FileTypeExt;
13-
use std::{
14-
collections::HashMap,
15-
io::{Error, ErrorKind},
16-
path::PathBuf,
17-
};
13+
use std::{collections::HashMap, io::Error, path::PathBuf};
1814

1915
const TRASH_SUPPORTED: bool = cfg!(all(
2016
feature = "trash-support",
@@ -379,7 +375,7 @@ fn rm(
379375
);
380376

381377
let result = if let Err(e) = interaction {
382-
Err(Error::new(ErrorKind::Other, &*e.to_string()))
378+
Err(Error::other(&*e.to_string()))
383379
} else if interactive && !confirmed {
384380
Ok(())
385381
} else if TRASH_SUPPORTED && (trash || (rm_always_trash && !permanent)) {
@@ -389,7 +385,7 @@ fn rm(
389385
))]
390386
{
391387
trash::delete(&f).map_err(|e: trash::Error| {
392-
Error::new(ErrorKind::Other, format!("{e:?}\nTry '--permanent' flag"))
388+
Error::other(format!("{e:?}\nTry '--permanent' flag"))
393389
})
394390
}
395391

crates/nu-command/src/filters/tee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<R: Read> Read for IoTee<R> {
394394
if let Some(thread) = self.thread.take() {
395395
if thread.is_finished() {
396396
if let Err(err) = thread.join().unwrap_or_else(|_| Err(panic_error())) {
397-
return Err(io::Error::new(io::ErrorKind::Other, err));
397+
return Err(io::Error::other(err));
398398
}
399399
} else {
400400
self.thread = Some(thread)
@@ -405,7 +405,7 @@ impl<R: Read> Read for IoTee<R> {
405405
self.sender = None;
406406
if let Some(thread) = self.thread.take() {
407407
if let Err(err) = thread.join().unwrap_or_else(|_| Err(panic_error())) {
408-
return Err(io::Error::new(io::ErrorKind::Other, err));
408+
return Err(io::Error::other(err));
409409
}
410410
}
411411
} else if let Some(sender) = self.sender.as_mut() {

crates/nu-json/src/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl io::Write for WriterFormatter<'_, '_> {
437437
fn io_error<E>(_: E) -> io::Error {
438438
// Value does not matter because fmt::Debug and fmt::Display impls
439439
// below just map it to fmt::Error
440-
io::Error::new(io::ErrorKind::Other, "fmt error")
440+
io::Error::other("fmt error")
441441
}
442442
let s = str::from_utf8(buf).map_err(io_error)?;
443443
self.inner.write_str(s).map_err(io_error)?;

crates/nu-protocol/src/engine/stack_out_dest.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ impl StackOutDest {
9191

9292
fn push_stdout(&mut self, stdout: OutDest) -> Option<OutDest> {
9393
let stdout = mem::replace(&mut self.stdout, stdout);
94-
mem::replace(&mut self.parent_stdout, Some(stdout))
94+
self.parent_stdout.replace(stdout)
9595
}
9696

9797
fn push_stderr(&mut self, stderr: OutDest) -> Option<OutDest> {
9898
let stderr = mem::replace(&mut self.stderr, stderr);
99-
mem::replace(&mut self.parent_stderr, Some(stderr))
99+
self.parent_stderr.replace(stderr)
100100
}
101101
}
102102

@@ -118,13 +118,13 @@ impl<'a> StackIoGuard<'a> {
118118

119119
let (old_pipe_stdout, old_parent_stdout) = match stdout {
120120
Some(Redirection::Pipe(stdout)) => {
121-
let old = mem::replace(&mut out_dest.pipe_stdout, Some(stdout));
121+
let old = out_dest.pipe_stdout.replace(stdout);
122122
(old, out_dest.parent_stdout.take())
123123
}
124124
Some(Redirection::File(file)) => {
125125
let file = OutDest::from(file);
126126
(
127-
mem::replace(&mut out_dest.pipe_stdout, Some(file.clone())),
127+
out_dest.pipe_stdout.replace(file.clone()),
128128
out_dest.push_stdout(file),
129129
)
130130
}
@@ -133,7 +133,7 @@ impl<'a> StackIoGuard<'a> {
133133

134134
let (old_pipe_stderr, old_parent_stderr) = match stderr {
135135
Some(Redirection::Pipe(stderr)) => {
136-
let old = mem::replace(&mut out_dest.pipe_stderr, Some(stderr));
136+
let old = out_dest.pipe_stderr.replace(stderr);
137137
(old, out_dest.parent_stderr.take())
138138
}
139139
Some(Redirection::File(file)) => (
@@ -192,7 +192,7 @@ pub struct StackCollectValueGuard<'a> {
192192

193193
impl<'a> StackCollectValueGuard<'a> {
194194
pub(crate) fn new(stack: &'a mut Stack) -> Self {
195-
let old_pipe_stdout = mem::replace(&mut stack.out_dest.pipe_stdout, Some(OutDest::Value));
195+
let old_pipe_stdout = stack.out_dest.pipe_stdout.replace(OutDest::Value);
196196
let old_pipe_stderr = stack.out_dest.pipe_stderr.take();
197197
Self {
198198
stack,
@@ -233,7 +233,7 @@ pub struct StackCallArgGuard<'a> {
233233

234234
impl<'a> StackCallArgGuard<'a> {
235235
pub(crate) fn new(stack: &'a mut Stack) -> Self {
236-
let old_pipe_stdout = mem::replace(&mut stack.out_dest.pipe_stdout, Some(OutDest::Value));
236+
let old_pipe_stdout = stack.out_dest.pipe_stdout.replace(OutDest::Value);
237237
let old_pipe_stderr = stack.out_dest.pipe_stderr.take();
238238

239239
let old_stdout = stack

crates/nu-system/src/util.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ pub fn kill_by_pid(pid: i64) -> io::Result<()> {
88
let output = cmd.output()?;
99

1010
if !output.status.success() {
11-
return Err(io::Error::new(
12-
io::ErrorKind::Other,
13-
"failed to kill process",
14-
));
11+
return Err(io::Error::other("failed to kill process"));
1512
}
1613

1714
Ok(())

0 commit comments

Comments
 (0)