mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
fix a lot of clippy warnings
This commit is contained in:
@@ -136,7 +136,8 @@ fn basename(fullname: &str, suffix: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
// can be replaced with strip_suffix once the minimum rust version is 1.45
|
||||
// can be replaced with strip_suffix once MSRV is 1.45
|
||||
#[allow(clippy::manual_strip)]
|
||||
fn strip_suffix(name: &str, suffix: &str) -> String {
|
||||
if name == suffix {
|
||||
return name.to_owned();
|
||||
|
||||
+1
-1
@@ -1108,7 +1108,7 @@ fn context_for(src: &Path, dest: &Path) -> String {
|
||||
|
||||
/// Implements a simple backup copy for the destination file.
|
||||
/// TODO: for the backup, should this function be replaced by `copy_file(...)`?
|
||||
fn backup_dest(dest: &Path, backup_path: &PathBuf) -> CopyResult<PathBuf> {
|
||||
fn backup_dest(dest: &Path, backup_path: &Path) -> CopyResult<PathBuf> {
|
||||
fs::copy(dest, &backup_path)?;
|
||||
Ok(backup_path.into())
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ impl Iterator for Sieve {
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<u64> {
|
||||
while let Some(n) = self.inner.next() {
|
||||
for n in &mut self.inner {
|
||||
let mut prime = true;
|
||||
while let Some((next, inc)) = self.filts.peek() {
|
||||
// need to keep checking the min element of the heap
|
||||
|
||||
@@ -14,7 +14,7 @@ pub fn parse_obsolete(src: &str) -> Option<Result<impl Iterator<Item = OsString>
|
||||
let mut num_end = 0usize;
|
||||
let mut has_num = false;
|
||||
let mut last_char = 0 as char;
|
||||
while let Some((n, c)) = chars.next() {
|
||||
for (n, c) in &mut chars {
|
||||
if c.is_numeric() {
|
||||
has_num = true;
|
||||
num_end = n;
|
||||
@@ -109,7 +109,7 @@ pub fn parse_num(src: &str) -> Result<(usize, bool), ParseError> {
|
||||
let mut num_end = 0usize;
|
||||
let mut last_char = 0 as char;
|
||||
let mut num_count = 0usize;
|
||||
while let Some((n, c)) = chars.next() {
|
||||
for (n, c) in &mut chars {
|
||||
if c.is_numeric() {
|
||||
num_end = n;
|
||||
num_count += 1;
|
||||
|
||||
@@ -520,6 +520,7 @@ fn copy_file_to_file(file: &Path, target: &Path, b: &Behavior) -> i32 {
|
||||
///
|
||||
/// If the copy system call fails, we print a verbose error and return an empty error value.
|
||||
///
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn copy(from: &Path, to: &Path, b: &Behavior) -> Result<(), ()> {
|
||||
if b.compare && !need_copy(from, to, b) {
|
||||
return Ok(());
|
||||
|
||||
@@ -218,6 +218,7 @@ struct LongFormat {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn from(options: clap::ArgMatches) -> Config {
|
||||
let (mut format, opt) = if let Some(format_) = options.value_of(options::FORMAT) {
|
||||
(
|
||||
|
||||
@@ -73,6 +73,7 @@ impl Chunk {
|
||||
/// * `lines`: The recycled vector to fill with lines. Must be empty.
|
||||
/// * `settings`: The global settings.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[allow(clippy::borrowed_box)]
|
||||
pub fn read(
|
||||
sender_option: &mut Option<SyncSender<Chunk>>,
|
||||
mut buffer: Vec<u8>,
|
||||
@@ -164,6 +165,7 @@ fn parse_lines<'a>(
|
||||
/// The remaining bytes must be copied to the start of the buffer for the next invocation,
|
||||
/// if another invocation is necessary, which is determined by the other return value.
|
||||
/// * Whether this function should be called again.
|
||||
#[allow(clippy::borrowed_box)]
|
||||
fn read_to_buffer(
|
||||
file: &mut Box<dyn Read + Send>,
|
||||
next_files: &mut impl Iterator<Item = Box<dyn Read + Send>>,
|
||||
|
||||
@@ -200,6 +200,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
split(&settings)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct Settings {
|
||||
prefix: String,
|
||||
numeric_suffix: bool,
|
||||
@@ -210,7 +211,7 @@ struct Settings {
|
||||
filter: Option<String>,
|
||||
strategy: String,
|
||||
strategy_param: String,
|
||||
verbose: bool,
|
||||
verbose: bool, // TODO: warning: field is never read: `verbose`
|
||||
}
|
||||
|
||||
trait Splitter {
|
||||
|
||||
@@ -199,6 +199,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::if_same_then_else)]
|
||||
if matches.is_present(options::FILE_SYSTEM) {
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
syncfs(files);
|
||||
|
||||
@@ -265,11 +265,10 @@ impl Parser {
|
||||
fn boolop(&mut self, op: Symbol) {
|
||||
if op == Symbol::BoolOp(OsString::from("-a")) {
|
||||
self.term();
|
||||
self.stack.push(op);
|
||||
} else {
|
||||
self.expr();
|
||||
self.stack.push(op);
|
||||
}
|
||||
self.stack.push(op);
|
||||
}
|
||||
|
||||
/// Parse a (possible) unary argument test (string length or file
|
||||
|
||||
@@ -145,14 +145,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||
|| matches.is_present(options::sources::CURRENT)
|
||||
{
|
||||
let timestamp = if matches.is_present(options::sources::DATE) {
|
||||
parse_date(matches.value_of(options::sources::DATE).unwrap().as_ref())
|
||||
parse_date(matches.value_of(options::sources::DATE).unwrap())
|
||||
} else {
|
||||
parse_timestamp(
|
||||
matches
|
||||
.value_of(options::sources::CURRENT)
|
||||
.unwrap()
|
||||
.as_ref(),
|
||||
)
|
||||
parse_timestamp(matches.value_of(options::sources::CURRENT).unwrap())
|
||||
};
|
||||
(timestamp, timestamp)
|
||||
} else {
|
||||
|
||||
@@ -110,7 +110,7 @@ impl<'a> Iterator for ExpandSet<'a> {
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
// while the Range has elements, try to return chars from it
|
||||
// but make sure that they actually turn out to be Chars!
|
||||
while let Some(n) = self.range.next() {
|
||||
for n in &mut self.range {
|
||||
if let Some(c) = from_u32(n) {
|
||||
return Some(c);
|
||||
}
|
||||
|
||||
@@ -551,10 +551,11 @@ impl Who {
|
||||
" ?".into()
|
||||
};
|
||||
|
||||
let mut s = ut.host();
|
||||
if self.do_lookup {
|
||||
s = safe_unwrap!(ut.canon_host());
|
||||
}
|
||||
let s = if self.do_lookup {
|
||||
safe_unwrap!(ut.canon_host())
|
||||
} else {
|
||||
ut.host()
|
||||
};
|
||||
let hoststr = if s.is_empty() { s } else { format!("({})", s) };
|
||||
|
||||
self.print_line(
|
||||
|
||||
@@ -179,7 +179,7 @@ impl MountInfo {
|
||||
/* for Irix 6.5 */
|
||||
| "ignore" => self.dummy = true,
|
||||
_ => self.dummy = self.fs_type == "none"
|
||||
&& self.mount_option.find(MOUNT_OPT_BIND).is_none(),
|
||||
&& !self.mount_option.contains(MOUNT_OPT_BIND)
|
||||
}
|
||||
// set MountInfo::remote
|
||||
#[cfg(windows)]
|
||||
|
||||
@@ -40,6 +40,7 @@ pub enum ExitStatus {
|
||||
Signal(i32),
|
||||
}
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
impl ExitStatus {
|
||||
fn from_std_status(status: StdExitStatus) -> Self {
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -34,7 +34,7 @@ fn test_base32_encode_file() {
|
||||
|
||||
#[test]
|
||||
fn test_decode() {
|
||||
for decode_param in vec!["-d", "--decode"] {
|
||||
for decode_param in &["-d", "--decode"] {
|
||||
let input = "JBSWY3DPFQQFO33SNRSCC===\n";
|
||||
new_ucmd!()
|
||||
.arg(decode_param)
|
||||
@@ -56,7 +56,7 @@ fn test_garbage() {
|
||||
|
||||
#[test]
|
||||
fn test_ignore_garbage() {
|
||||
for ignore_garbage_param in vec!["-i", "--ignore-garbage"] {
|
||||
for ignore_garbage_param in &["-i", "--ignore-garbage"] {
|
||||
let input = "JBSWY\x013DPFQ\x02QFO33SNRSCC===\n";
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
@@ -69,7 +69,7 @@ fn test_ignore_garbage() {
|
||||
|
||||
#[test]
|
||||
fn test_wrap() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
let input = "The quick brown fox jumps over the lazy dog.";
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
@@ -84,16 +84,21 @@ fn test_wrap() {
|
||||
|
||||
#[test]
|
||||
fn test_wrap_no_arg() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
new_ucmd!().arg(wrap_param).fails().stderr_only(format!(
|
||||
"error: The argument '--wrap <wrap>\' requires a value but none was supplied\n\nUSAGE:\n base32 [OPTION]... [FILE]\n\nFor more information try --help"
|
||||
));
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
let expected_stderr = "error: The argument '--wrap <wrap>\' requires a value but none was \
|
||||
supplied\n\nUSAGE:\n base32 [OPTION]... [FILE]\n\nFor more \
|
||||
information try --help"
|
||||
.to_string();
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.fails()
|
||||
.stderr_only(expected_stderr);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wrap_bad_arg() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.arg("b")
|
||||
|
||||
@@ -26,7 +26,7 @@ fn test_base64_encode_file() {
|
||||
|
||||
#[test]
|
||||
fn test_decode() {
|
||||
for decode_param in vec!["-d", "--decode"] {
|
||||
for decode_param in &["-d", "--decode"] {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==";
|
||||
new_ucmd!()
|
||||
.arg(decode_param)
|
||||
@@ -48,7 +48,7 @@ fn test_garbage() {
|
||||
|
||||
#[test]
|
||||
fn test_ignore_garbage() {
|
||||
for ignore_garbage_param in vec!["-i", "--ignore-garbage"] {
|
||||
for ignore_garbage_param in &["-i", "--ignore-garbage"] {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0";
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
@@ -61,7 +61,7 @@ fn test_ignore_garbage() {
|
||||
|
||||
#[test]
|
||||
fn test_wrap() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
let input = "The quick brown fox jumps over the lazy dog.";
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
@@ -74,7 +74,7 @@ fn test_wrap() {
|
||||
|
||||
#[test]
|
||||
fn test_wrap_no_arg() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
new_ucmd!().arg(wrap_param).fails().stderr_contains(
|
||||
&"The argument '--wrap <wrap>' requires a value but none was supplied",
|
||||
);
|
||||
@@ -83,7 +83,7 @@ fn test_wrap_no_arg() {
|
||||
|
||||
#[test]
|
||||
fn test_wrap_bad_arg() {
|
||||
for wrap_param in vec!["-w", "--wrap"] {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.arg("b")
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::ffi::OsStr;
|
||||
|
||||
#[test]
|
||||
fn test_help() {
|
||||
for help_flg in vec!["-h", "--help"] {
|
||||
for help_flg in &["-h", "--help"] {
|
||||
new_ucmd!()
|
||||
.arg(&help_flg)
|
||||
.succeeds()
|
||||
@@ -15,7 +15,7 @@ fn test_help() {
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
for version_flg in vec!["-V", "--version"] {
|
||||
for version_flg in &["-V", "--version"] {
|
||||
assert!(new_ucmd!()
|
||||
.arg(&version_flg)
|
||||
.succeeds()
|
||||
@@ -59,7 +59,7 @@ fn test_dont_remove_suffix() {
|
||||
|
||||
#[test]
|
||||
fn test_multiple_param() {
|
||||
for multiple_param in vec!["-a", "--multiple"] {
|
||||
for &multiple_param in &["-a", "--multiple"] {
|
||||
let path = "/foo/bar/baz";
|
||||
new_ucmd!()
|
||||
.args(&[multiple_param, path, path])
|
||||
@@ -70,7 +70,7 @@ fn test_multiple_param() {
|
||||
|
||||
#[test]
|
||||
fn test_suffix_param() {
|
||||
for suffix_param in vec!["-s", "--suffix"] {
|
||||
for &suffix_param in &["-s", "--suffix"] {
|
||||
let path = "/foo/bar/baz.exe";
|
||||
new_ucmd!()
|
||||
.args(&[suffix_param, ".exe", path, path])
|
||||
@@ -81,7 +81,7 @@ fn test_suffix_param() {
|
||||
|
||||
#[test]
|
||||
fn test_zero_param() {
|
||||
for zero_param in vec!["-z", "--zero"] {
|
||||
for &zero_param in &["-z", "--zero"] {
|
||||
let path = "/foo/bar/baz";
|
||||
new_ucmd!()
|
||||
.args(&[zero_param, "-a", path, path])
|
||||
@@ -91,7 +91,12 @@ fn test_zero_param() {
|
||||
}
|
||||
|
||||
fn expect_error(input: Vec<&str>) {
|
||||
assert!(new_ucmd!().args(&input).fails().no_stdout().stderr().len() > 0);
|
||||
assert!(!new_ucmd!()
|
||||
.args(&input)
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_str()
|
||||
.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+13
-10
@@ -237,7 +237,7 @@ fn test_numbered_lines_no_trailing_newline() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin_show_nonprinting() {
|
||||
for same_param in vec!["-v", "--show-nonprinting"] {
|
||||
for same_param in &["-v", "--show-nonprinting"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
@@ -248,7 +248,7 @@ fn test_stdin_show_nonprinting() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin_show_tabs() {
|
||||
for same_param in vec!["-T", "--show-tabs"] {
|
||||
for same_param in &["-T", "--show-tabs"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
@@ -259,7 +259,7 @@ fn test_stdin_show_tabs() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin_show_ends() {
|
||||
for same_param in vec!["-E", "--show-ends"] {
|
||||
for &same_param in &["-E", "--show-ends"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param, "-"])
|
||||
.pipe_in("\t\0\n\t")
|
||||
@@ -270,7 +270,7 @@ fn test_stdin_show_ends() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin_show_all() {
|
||||
for same_param in vec!["-A", "--show-all"] {
|
||||
for same_param in &["-A", "--show-all"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
@@ -299,7 +299,7 @@ fn test_stdin_nonprinting_and_tabs() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin_squeeze_blank() {
|
||||
for same_param in vec!["-s", "--squeeze-blank"] {
|
||||
for same_param in &["-s", "--squeeze-blank"] {
|
||||
new_ucmd!()
|
||||
.arg(same_param)
|
||||
.pipe_in("\n\na\n\n\n\n\nb\n\n\n")
|
||||
@@ -310,7 +310,7 @@ fn test_stdin_squeeze_blank() {
|
||||
|
||||
#[test]
|
||||
fn test_stdin_number_non_blank() {
|
||||
for same_param in vec!["-b", "--number-nonblank"] {
|
||||
for same_param in &["-b", "--number-nonblank"] {
|
||||
new_ucmd!()
|
||||
.arg(same_param)
|
||||
.arg("-")
|
||||
@@ -322,7 +322,7 @@ fn test_stdin_number_non_blank() {
|
||||
|
||||
#[test]
|
||||
fn test_non_blank_overrides_number() {
|
||||
for same_param in vec!["-b", "--number-nonblank"] {
|
||||
for &same_param in &["-b", "--number-nonblank"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param, "-"])
|
||||
.pipe_in("\na\nb\n\n\nc")
|
||||
@@ -333,7 +333,7 @@ fn test_non_blank_overrides_number() {
|
||||
|
||||
#[test]
|
||||
fn test_squeeze_blank_before_numbering() {
|
||||
for same_param in vec!["-s", "--squeeze-blank"] {
|
||||
for &same_param in &["-s", "--squeeze-blank"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param, "-n", "-"])
|
||||
.pipe_in("a\n\n\nb")
|
||||
@@ -408,7 +408,10 @@ fn test_domain_socket() {
|
||||
use std::thread;
|
||||
use unix_socket::UnixListener;
|
||||
|
||||
let dir = tempfile::Builder::new().prefix("unix_socket").tempdir().expect("failed to create dir");
|
||||
let dir = tempfile::Builder::new()
|
||||
.prefix("unix_socket")
|
||||
.tempdir()
|
||||
.expect("failed to create dir");
|
||||
let socket_path = dir.path().join("sock");
|
||||
let listener = UnixListener::bind(&socket_path).expect("failed to create socket");
|
||||
|
||||
@@ -426,7 +429,7 @@ fn test_domain_socket() {
|
||||
|
||||
let child = new_ucmd!().args(&[socket_path]).run_no_wait();
|
||||
barrier.wait();
|
||||
let stdout = &child.wait_with_output().unwrap().stdout.clone();
|
||||
let stdout = &child.wait_with_output().unwrap().stdout;
|
||||
let output = String::from_utf8_lossy(&stdout);
|
||||
assert_eq!("a\tb", output);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ fn test_invalid_option() {
|
||||
new_ucmd!().arg("-w").arg("/").fails();
|
||||
}
|
||||
|
||||
static DIR: &'static str = "/tmp";
|
||||
static DIR: &str = "/tmp";
|
||||
|
||||
#[test]
|
||||
fn test_invalid_group() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user