From 2a2126c40a6330d5dc54c6c3a54e58d0637b101c Mon Sep 17 00:00:00 2001 From: David Peter Date: Tue, 27 Jul 2021 08:38:09 +0200 Subject: [PATCH] Fix clippy warnings --- .github/workflows/CICD.yml | 2 +- README.md | 2 +- build.rs | 2 +- src/exec/mod.rs | 5 +---- src/exit_codes.rs | 12 ++++++------ src/filesystem.rs | 8 ++++---- src/main.rs | 10 +++++----- src/output.rs | 6 +++--- src/walk.rs | 8 ++++---- tests/testenv/mod.rs | 13 ++++++++----- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 1f80cb3..22ba12d 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1,7 +1,7 @@ name: CICD env: - MIN_SUPPORTED_RUST_VERSION: "1.40.0" + MIN_SUPPORTED_RUST_VERSION: "1.42.0" CICD_INTERMEDIATES_DIR: "_cicd-intermediates" on: diff --git a/README.md b/README.md index 8c991d1..66d5752 100644 --- a/README.md +++ b/README.md @@ -621,7 +621,7 @@ With Rust's package manager [cargo](https://github.com/rust-lang/cargo), you can ``` cargo install fd-find ``` -Note that rust version *1.36.0* or later is required. +Note that rust version *1.42.0* or later is required. ### From binaries diff --git a/build.rs b/build.rs index a560325..ddf9e15 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,7 @@ use clap::Shell; include!("src/app.rs"); fn main() { - let min_version = "1.36"; + let min_version = "1.42"; match version_check::is_min_version(min_version) { Some(true) => {} diff --git a/src/exec/mod.rs b/src/exec/mod.rs index c47e32c..f24c0e3 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -201,10 +201,7 @@ enum ArgumentTemplate { impl ArgumentTemplate { pub fn has_tokens(&self) -> bool { - match self { - ArgumentTemplate::Tokens(_) => true, - _ => false, - } + matches!(self, ArgumentTemplate::Tokens(_)) } /// Generate an argument from this template. If path_separator is Some, then it will replace diff --git a/src/exit_codes.rs b/src/exit_codes.rs index 96bce96..720440f 100644 --- a/src/exit_codes.rs +++ b/src/exit_codes.rs @@ -5,9 +5,9 @@ pub enum ExitCode { KilledBySigint, } -impl Into for ExitCode { - fn into(self) -> i32 { - match self { +impl From for i32 { + fn from(code: ExitCode) -> Self { + match code { ExitCode::Success => 0, ExitCode::GeneralError => 1, ExitCode::KilledBySigint => 130, @@ -16,13 +16,13 @@ impl Into for ExitCode { } impl ExitCode { - fn is_error(&self) -> bool { - *self != ExitCode::Success + fn is_error(self) -> bool { + self != ExitCode::Success } } pub fn merge_exitcodes(results: &[ExitCode]) -> ExitCode { - if results.iter().any(ExitCode::is_error) { + if results.iter().any(|&c| ExitCode::is_error(c)) { return ExitCode::GeneralError; } ExitCode::Success diff --git a/src/filesystem.rs b/src/filesystem.rs index 15ca56d..19fc0e6 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -68,22 +68,22 @@ pub fn is_empty(entry: &walk::DirEntry) -> bool { } #[cfg(any(unix, target_os = "redox"))] -pub fn is_socket(ft: &fs::FileType) -> bool { +pub fn is_socket(ft: fs::FileType) -> bool { ft.is_socket() } #[cfg(windows)] -pub fn is_socket(_: &fs::FileType) -> bool { +pub fn is_socket(_: fs::FileType) -> bool { false } #[cfg(any(unix, target_os = "redox"))] -pub fn is_pipe(ft: &fs::FileType) -> bool { +pub fn is_pipe(ft: fs::FileType) -> bool { ft.is_fifo() } #[cfg(windows)] -pub fn is_pipe(_: &fs::FileType) -> bool { +pub fn is_pipe(_: fs::FileType) -> bool { false } diff --git a/src/main.rs b/src/main.rs index 6f0eece..4b5f71c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -331,20 +331,20 @@ fn run() -> Result { .value_of("max-depth") .or_else(|| matches.value_of("rg-depth")) .or_else(|| matches.value_of("exact-depth")) - .map(|n| usize::from_str_radix(n, 10)) + .map(|n| n.parse::()) .transpose() .context("Failed to parse argument to --max-depth/--exact-depth")?, min_depth: matches .value_of("min-depth") .or_else(|| matches.value_of("exact-depth")) - .map(|n| usize::from_str_radix(n, 10)) + .map(|n| n.parse::()) .transpose() .context("Failed to parse argument to --min-depth/--exact-depth")?, prune: matches.is_present("prune"), threads: std::cmp::max( matches .value_of("threads") - .map(|n| usize::from_str_radix(n, 10)) + .map(|n| n.parse::()) .transpose() .context("Failed to parse number of threads")? .map(|n| { @@ -360,7 +360,7 @@ fn run() -> Result { ), max_buffer_time: matches .value_of("max-buffer-time") - .map(|n| u64::from_str_radix(n, 10)) + .map(|n| n.parse::()) .transpose() .context("Failed to parse max. buffer time argument")? .map(time::Duration::from_millis), @@ -420,7 +420,7 @@ fn run() -> Result { path_separator, max_results: matches .value_of("max-results") - .map(|n| usize::from_str_radix(n, 10)) + .map(|n| n.parse::()) .transpose() .context("Failed to parse --max-results argument")? .filter(|&n| n > 0) diff --git a/src/output.rs b/src/output.rs index 008f3a9..aa5e344 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,5 +1,5 @@ use std::io::{self, StdoutLock, Write}; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::process; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -17,12 +17,12 @@ fn replace_path_separator(path: &str, new_path_separator: &str) -> String { // TODO: this function is performance critical and can probably be optimized pub fn print_entry( stdout: &mut StdoutLock, - entry: &PathBuf, + entry: &Path, config: &Options, wants_to_quit: &Arc, ) { let path = if entry.is_absolute() { - entry.as_path() + entry } else { strip_current_dir(entry) }; diff --git a/src/walk.rs b/src/walk.rs index 456b717..7b0db30 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -426,8 +426,8 @@ fn spawn_senders( if (!file_types.files && entry_type.is_file()) || (!file_types.directories && entry_type.is_dir()) || (!file_types.symlinks && entry_type.is_symlink()) - || (!file_types.sockets && filesystem::is_socket(entry_type)) - || (!file_types.pipes && filesystem::is_pipe(entry_type)) + || (!file_types.sockets && filesystem::is_socket(*entry_type)) + || (!file_types.pipes && filesystem::is_pipe(*entry_type)) || (file_types.executables_only && !entry .metadata() @@ -437,8 +437,8 @@ fn spawn_senders( || !(entry_type.is_file() || entry_type.is_dir() || entry_type.is_symlink() - || filesystem::is_socket(entry_type) - || filesystem::is_pipe(entry_type)) + || filesystem::is_socket(*entry_type) + || filesystem::is_pipe(*entry_type)) { return ignore::WalkState::Continue; } diff --git a/tests/testenv/mod.rs b/tests/testenv/mod.rs index 6b58fc0..cc439bc 100644 --- a/tests/testenv/mod.rs +++ b/tests/testenv/mod.rs @@ -119,7 +119,7 @@ fn normalize_output(s: &str, trim_start: bool, normalize_line: bool) -> String { let line = line.replace('/', &std::path::MAIN_SEPARATOR.to_string()); if normalize_line { let mut words: Vec<_> = line.split_whitespace().collect(); - words.sort(); + words.sort_unstable(); return words.join(" "); } line @@ -197,7 +197,7 @@ impl TestEnv { // Check for exit status. if !output.status.success() { - panic!(format_exit_error(args, &output)); + panic!("{}", format_exit_error(args, &output)); } output @@ -236,7 +236,7 @@ impl TestEnv { // Compare actual output to expected output. if expected != actual { - panic!(format_output_error(args, &expected, &actual)); + panic!("{}", format_output_error(args, &expected, &actual)); } } @@ -289,10 +289,13 @@ impl TestEnv { // Compare actual output to expected output. if !actual_err.trim_start().starts_with(&expected_error) { - panic!(format_output_error(args, &expected_error, &actual_err)); + panic!( + "{}", + format_output_error(args, &expected_error, &actual_err) + ); } } - return output.status; + output.status } }