Fix clippy warnings

This commit is contained in:
David Peter 2021-07-27 08:38:09 +02:00 committed by David Peter
parent db30bfc2b7
commit 2a2126c40a
10 changed files with 34 additions and 34 deletions

View File

@ -1,7 +1,7 @@
name: CICD name: CICD
env: env:
MIN_SUPPORTED_RUST_VERSION: "1.40.0" MIN_SUPPORTED_RUST_VERSION: "1.42.0"
CICD_INTERMEDIATES_DIR: "_cicd-intermediates" CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
on: on:

View File

@ -621,7 +621,7 @@ With Rust's package manager [cargo](https://github.com/rust-lang/cargo), you can
``` ```
cargo install fd-find 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 ### From binaries

View File

@ -5,7 +5,7 @@ use clap::Shell;
include!("src/app.rs"); include!("src/app.rs");
fn main() { fn main() {
let min_version = "1.36"; let min_version = "1.42";
match version_check::is_min_version(min_version) { match version_check::is_min_version(min_version) {
Some(true) => {} Some(true) => {}

View File

@ -201,10 +201,7 @@ enum ArgumentTemplate {
impl ArgumentTemplate { impl ArgumentTemplate {
pub fn has_tokens(&self) -> bool { pub fn has_tokens(&self) -> bool {
match self { matches!(self, ArgumentTemplate::Tokens(_))
ArgumentTemplate::Tokens(_) => true,
_ => false,
}
} }
/// Generate an argument from this template. If path_separator is Some, then it will replace /// Generate an argument from this template. If path_separator is Some, then it will replace

View File

@ -5,9 +5,9 @@ pub enum ExitCode {
KilledBySigint, KilledBySigint,
} }
impl Into<i32> for ExitCode { impl From<ExitCode> for i32 {
fn into(self) -> i32 { fn from(code: ExitCode) -> Self {
match self { match code {
ExitCode::Success => 0, ExitCode::Success => 0,
ExitCode::GeneralError => 1, ExitCode::GeneralError => 1,
ExitCode::KilledBySigint => 130, ExitCode::KilledBySigint => 130,
@ -16,13 +16,13 @@ impl Into<i32> for ExitCode {
} }
impl ExitCode { impl ExitCode {
fn is_error(&self) -> bool { fn is_error(self) -> bool {
*self != ExitCode::Success self != ExitCode::Success
} }
} }
pub fn merge_exitcodes(results: &[ExitCode]) -> ExitCode { 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; return ExitCode::GeneralError;
} }
ExitCode::Success ExitCode::Success

View File

@ -68,22 +68,22 @@ pub fn is_empty(entry: &walk::DirEntry) -> bool {
} }
#[cfg(any(unix, target_os = "redox"))] #[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() ft.is_socket()
} }
#[cfg(windows)] #[cfg(windows)]
pub fn is_socket(_: &fs::FileType) -> bool { pub fn is_socket(_: fs::FileType) -> bool {
false false
} }
#[cfg(any(unix, target_os = "redox"))] #[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() ft.is_fifo()
} }
#[cfg(windows)] #[cfg(windows)]
pub fn is_pipe(_: &fs::FileType) -> bool { pub fn is_pipe(_: fs::FileType) -> bool {
false false
} }

View File

@ -331,20 +331,20 @@ fn run() -> Result<ExitCode> {
.value_of("max-depth") .value_of("max-depth")
.or_else(|| matches.value_of("rg-depth")) .or_else(|| matches.value_of("rg-depth"))
.or_else(|| matches.value_of("exact-depth")) .or_else(|| matches.value_of("exact-depth"))
.map(|n| usize::from_str_radix(n, 10)) .map(|n| n.parse::<usize>())
.transpose() .transpose()
.context("Failed to parse argument to --max-depth/--exact-depth")?, .context("Failed to parse argument to --max-depth/--exact-depth")?,
min_depth: matches min_depth: matches
.value_of("min-depth") .value_of("min-depth")
.or_else(|| matches.value_of("exact-depth")) .or_else(|| matches.value_of("exact-depth"))
.map(|n| usize::from_str_radix(n, 10)) .map(|n| n.parse::<usize>())
.transpose() .transpose()
.context("Failed to parse argument to --min-depth/--exact-depth")?, .context("Failed to parse argument to --min-depth/--exact-depth")?,
prune: matches.is_present("prune"), prune: matches.is_present("prune"),
threads: std::cmp::max( threads: std::cmp::max(
matches matches
.value_of("threads") .value_of("threads")
.map(|n| usize::from_str_radix(n, 10)) .map(|n| n.parse::<usize>())
.transpose() .transpose()
.context("Failed to parse number of threads")? .context("Failed to parse number of threads")?
.map(|n| { .map(|n| {
@ -360,7 +360,7 @@ fn run() -> Result<ExitCode> {
), ),
max_buffer_time: matches max_buffer_time: matches
.value_of("max-buffer-time") .value_of("max-buffer-time")
.map(|n| u64::from_str_radix(n, 10)) .map(|n| n.parse::<u64>())
.transpose() .transpose()
.context("Failed to parse max. buffer time argument")? .context("Failed to parse max. buffer time argument")?
.map(time::Duration::from_millis), .map(time::Duration::from_millis),
@ -420,7 +420,7 @@ fn run() -> Result<ExitCode> {
path_separator, path_separator,
max_results: matches max_results: matches
.value_of("max-results") .value_of("max-results")
.map(|n| usize::from_str_radix(n, 10)) .map(|n| n.parse::<usize>())
.transpose() .transpose()
.context("Failed to parse --max-results argument")? .context("Failed to parse --max-results argument")?
.filter(|&n| n > 0) .filter(|&n| n > 0)

View File

@ -1,5 +1,5 @@
use std::io::{self, StdoutLock, Write}; use std::io::{self, StdoutLock, Write};
use std::path::{Path, PathBuf}; use std::path::Path;
use std::process; use std::process;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; 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 // TODO: this function is performance critical and can probably be optimized
pub fn print_entry( pub fn print_entry(
stdout: &mut StdoutLock, stdout: &mut StdoutLock,
entry: &PathBuf, entry: &Path,
config: &Options, config: &Options,
wants_to_quit: &Arc<AtomicBool>, wants_to_quit: &Arc<AtomicBool>,
) { ) {
let path = if entry.is_absolute() { let path = if entry.is_absolute() {
entry.as_path() entry
} else { } else {
strip_current_dir(entry) strip_current_dir(entry)
}; };

View File

@ -426,8 +426,8 @@ fn spawn_senders(
if (!file_types.files && entry_type.is_file()) if (!file_types.files && entry_type.is_file())
|| (!file_types.directories && entry_type.is_dir()) || (!file_types.directories && entry_type.is_dir())
|| (!file_types.symlinks && entry_type.is_symlink()) || (!file_types.symlinks && entry_type.is_symlink())
|| (!file_types.sockets && filesystem::is_socket(entry_type)) || (!file_types.sockets && filesystem::is_socket(*entry_type))
|| (!file_types.pipes && filesystem::is_pipe(entry_type)) || (!file_types.pipes && filesystem::is_pipe(*entry_type))
|| (file_types.executables_only || (file_types.executables_only
&& !entry && !entry
.metadata() .metadata()
@ -437,8 +437,8 @@ fn spawn_senders(
|| !(entry_type.is_file() || !(entry_type.is_file()
|| entry_type.is_dir() || entry_type.is_dir()
|| entry_type.is_symlink() || entry_type.is_symlink()
|| filesystem::is_socket(entry_type) || filesystem::is_socket(*entry_type)
|| filesystem::is_pipe(entry_type)) || filesystem::is_pipe(*entry_type))
{ {
return ignore::WalkState::Continue; return ignore::WalkState::Continue;
} }

View File

@ -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()); let line = line.replace('/', &std::path::MAIN_SEPARATOR.to_string());
if normalize_line { if normalize_line {
let mut words: Vec<_> = line.split_whitespace().collect(); let mut words: Vec<_> = line.split_whitespace().collect();
words.sort(); words.sort_unstable();
return words.join(" "); return words.join(" ");
} }
line line
@ -197,7 +197,7 @@ impl TestEnv {
// Check for exit status. // Check for exit status.
if !output.status.success() { if !output.status.success() {
panic!(format_exit_error(args, &output)); panic!("{}", format_exit_error(args, &output));
} }
output output
@ -236,7 +236,7 @@ impl TestEnv {
// Compare actual output to expected output. // Compare actual output to expected output.
if expected != actual { 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. // Compare actual output to expected output.
if !actual_err.trim_start().starts_with(&expected_error) { 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
} }
} }