Skip to content

Commit adb90c8

Browse files
committed
refactor: apply clippy rules
1 parent 02ac7b3 commit adb90c8

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/child.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{process, CmdResult, FunResult};
33
use os_pipe::PipeReader;
44
use std::any::Any;
55
use std::fmt::Display;
6-
use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Result};
6+
use std::io::{BufRead, BufReader, Error, Read, Result};
77
use std::process::{Child, ExitStatus};
88
use std::thread::JoinHandle;
99

@@ -37,9 +37,11 @@ impl CmdChildren {
3737
let last_child_res = last_child.wait(true);
3838
let other_children_res = Self::wait_children(&mut self.children);
3939

40-
self.ignore_error
41-
.then_some(Ok(()))
42-
.unwrap_or(last_child_res.and(other_children_res))
40+
if self.ignore_error {
41+
Ok(())
42+
} else {
43+
last_child_res.and(other_children_res)
44+
}
4345
}
4446

4547
fn wait_children(children: &mut Vec<CmdChild>) -> CmdResult {
@@ -166,9 +168,11 @@ impl FunChildren {
166168
let other_children_res = CmdChildren::wait_children(&mut self.children);
167169
let _ = stderr_thread.join();
168170

169-
self.ignore_error
170-
.then_some(Ok(()))
171-
.unwrap_or(last_child_res.and(other_children_res))
171+
if self.ignore_error {
172+
Ok(())
173+
} else {
174+
last_child_res.and(other_children_res)
175+
}
172176
}
173177

174178
/// Returns the OS-assigned process identifiers associated with these children processes.
@@ -183,10 +187,11 @@ impl FunChildren {
183187
let last_child = self.children.pop().unwrap();
184188
let last_child_res = last_child.wait_with_all(capture_stderr, &mut stdout, &mut stderr);
185189
let other_children_res = CmdChildren::wait_children(&mut self.children);
186-
let cmd_result = self
187-
.ignore_error
188-
.then_some(Ok(()))
189-
.unwrap_or(last_child_res.and(other_children_res));
190+
let cmd_result = if self.ignore_error {
191+
Ok(())
192+
} else {
193+
last_child_res.and(other_children_res)
194+
};
190195

191196
let mut stdout: String = String::from_utf8_lossy(&stdout).into();
192197
if stdout.ends_with('\n') {
@@ -345,10 +350,9 @@ trait ChildOutcome: Display {
345350
if self.success() {
346351
Ok(())
347352
} else {
348-
Err(Error::new(
349-
ErrorKind::Other,
350-
format!("Running [{cmd}] exited with error; {self} at {file}:{line}"),
351-
))
353+
Err(Error::other(format!(
354+
"Running [{cmd}] exited with error; {self} at {file}:{line}"
355+
)))
352356
}
353357
}
354358
}
@@ -392,10 +396,9 @@ impl CmdChildHandle {
392396
format!("Killing process [{cmd}] failed with error: {e} at {file}:{line}"),
393397
)
394398
}),
395-
CmdChildHandle::Thread(_thread) => Err(Error::new(
396-
ErrorKind::Other,
397-
format!("Killing thread [{cmd}] failed: not supported at {file}:{line}"),
398-
)),
399+
CmdChildHandle::Thread(_thread) => Err(Error::other(format!(
400+
"Killing thread [{cmd}] failed: not supported at {file}:{line}"
401+
))),
399402
CmdChildHandle::SyncFn => Ok(()),
400403
}
401404
}

src/process.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::collections::HashMap;
1010
use std::ffi::{OsStr, OsString};
1111
use std::fmt;
1212
use std::fs::{File, OpenOptions};
13-
use std::io::{Error, ErrorKind, Result};
13+
use std::io::{Error, Result};
1414
use std::marker::PhantomData;
1515
use std::mem::take;
1616
use std::path::{Path, PathBuf};
@@ -150,11 +150,11 @@ pub(crate) fn pipefail_enabled() -> bool {
150150
thread_local! {
151151
/// Whether debug mode is enabled in the current thread.
152152
/// None means to use the global setting in [`DEBUG_ENABLED`].
153-
static DEBUG_OVERRIDE: Cell<Option<bool>> = Cell::new(None);
153+
static DEBUG_OVERRIDE: Cell<Option<bool>> = const { Cell::new(None) };
154154

155155
/// Whether pipefail mode is enabled in the current thread.
156156
/// None means to use the global setting in [`PIPEFAIL_ENABLED`].
157-
static PIPEFAIL_OVERRIDE: Cell<Option<bool>> = Cell::new(None);
157+
static PIPEFAIL_OVERRIDE: Cell<Option<bool>> = const { Cell::new(None) };
158158
}
159159

160160
/// Overrides the debug mode in the current thread, while the value is in scope.
@@ -622,19 +622,16 @@ impl Cmd {
622622

623623
fn run_cd_cmd(&self, current_dir: &mut PathBuf, file: &str, line: u32) -> CmdResult {
624624
if self.args.len() == 1 {
625-
return Err(Error::new(
626-
ErrorKind::Other,
627-
"{CD_CMD}: missing directory at {file}:{line}",
628-
));
625+
return Err(Error::other("{CD_CMD}: missing directory at {file}:{line}"));
629626
} else if self.args.len() > 2 {
630627
let err_msg = format!("{CD_CMD}: too many arguments at {file}:{line}");
631-
return Err(Error::new(ErrorKind::Other, err_msg));
628+
return Err(Error::other(err_msg));
632629
}
633630

634631
let dir = current_dir.join(&self.args[1]);
635632
if !dir.is_dir() {
636633
let err_msg = format!("{CD_CMD}: No such file or directory at {file}:{line}");
637-
return Err(Error::new(ErrorKind::Other, err_msg));
634+
return Err(Error::other(err_msg));
638635
}
639636

640637
dir.access(AccessMode::EXECUTE)?;

0 commit comments

Comments
 (0)