From 068bebb4e6d8f161aa11f70579aa7901be21ded1 Mon Sep 17 00:00:00 2001 From: David Peter Date: Sun, 22 Aug 2021 16:05:03 +0200 Subject: [PATCH] Fix remaining clippy warnings --- src/hyperfine/benchmark.rs | 37 ++++++++++++++++++++++--------- src/hyperfine/export/csv.rs | 3 +-- src/hyperfine/format.rs | 5 ++--- src/hyperfine/parameter_range.rs | 3 ++- src/hyperfine/timer/unix_timer.rs | 1 + src/hyperfine/types.rs | 13 ++++++----- src/main.rs | 6 +++-- 7 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/hyperfine/benchmark.rs b/src/hyperfine/benchmark.rs index 0841c1a..bde077b 100644 --- a/src/hyperfine/benchmark.rs +++ b/src/hyperfine/benchmark.rs @@ -147,10 +147,14 @@ pub fn mean_shell_spawning_time( } } - if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } + if let Some(bar) = progress_bar.as_ref() { + bar.inc(1) + } } - if let Some(bar) = progress_bar.as_ref() { bar.finish_and_clear() } + if let Some(bar) = progress_bar.as_ref() { + bar.finish_and_clear() + } Ok(TimingResult { time_real: mean(×_real), @@ -276,9 +280,13 @@ pub fn run_benchmark( options.failure_action, None, )?; - if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } + if let Some(bar) = progress_bar.as_ref() { + bar.inc(1) + } + } + if let Some(bar) = progress_bar.as_ref() { + bar.finish_and_clear() } - if let Some(bar) = progress_bar.as_ref() { bar.finish_and_clear() } } // Set up progress bar (and spinner for initial measurement) @@ -331,8 +339,12 @@ pub fn run_benchmark( all_succeeded = all_succeeded && success; // Re-configure the progress bar - if let Some(bar) = progress_bar.as_ref() { bar.set_length(count) } - if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } + if let Some(bar) = progress_bar.as_ref() { + bar.set_length(count) + } + if let Some(bar) = progress_bar.as_ref() { + bar.inc(1) + } // Gather statistics for _ in 0..count_remaining { @@ -343,8 +355,9 @@ pub fn run_benchmark( format!("Current estimate: {}", mean.to_string().green()) }; - if let Some(bar) = progress_bar - .as_ref() { bar.set_message(msg.to_owned()) } + if let Some(bar) = progress_bar.as_ref() { + bar.set_message(msg.to_owned()) + } let (res, status) = time_shell_command( &options.shell, @@ -362,10 +375,14 @@ pub fn run_benchmark( all_succeeded = all_succeeded && success; - if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } + if let Some(bar) = progress_bar.as_ref() { + bar.inc(1) + } } - if let Some(bar) = progress_bar.as_ref() { bar.finish_and_clear() } + if let Some(bar) = progress_bar.as_ref() { + bar.finish_and_clear() + } // Compute statistical quantities let t_num = times_real.len(); diff --git a/src/hyperfine/export/csv.rs b/src/hyperfine/export/csv.rs index ef2cc23..12d9b75 100644 --- a/src/hyperfine/export/csv.rs +++ b/src/hyperfine/export/csv.rs @@ -32,8 +32,7 @@ impl Exporter for CsvExporter { } for res in results { - let mut fields = Vec::new(); - fields.push(Cow::Borrowed(res.command.as_bytes())); + let mut fields = vec![Cow::Borrowed(res.command.as_bytes())]; for f in &[ res.mean, res.stddev, res.median, res.user, res.system, res.min, res.max, ] { diff --git a/src/hyperfine/format.rs b/src/hyperfine/format.rs index 1204c46..cc5f5d5 100644 --- a/src/hyperfine/format.rs +++ b/src/hyperfine/format.rs @@ -3,9 +3,8 @@ use crate::hyperfine::units::{Second, Unit}; /// Format the given duration as a string. The output-unit can be enforced by setting `unit` to /// `Some(target_unit)`. If `unit` is `None`, it will be determined automatically. pub fn format_duration(duration: Second, unit: Option) -> String { - match format_duration_unit(duration, unit) { - (duration_fmt, _) => duration_fmt, - } + let (duration_fmt, _) = format_duration_unit(duration, unit); + duration_fmt } /// Like `format_duration`, but returns the target unit as well. diff --git a/src/hyperfine/parameter_range.rs b/src/hyperfine/parameter_range.rs index 55b7aa9..7115e3c 100644 --- a/src/hyperfine/parameter_range.rs +++ b/src/hyperfine/parameter_range.rs @@ -118,7 +118,8 @@ fn build_parameterized_commands<'a, T: Numeric>( for cmd in &command_strings { let name = command_names .get(i) - .or_else(|| command_names.get(0)).copied(); + .or_else(|| command_names.get(0)) + .copied(); commands.push(Command::new_parametrized( name, cmd, diff --git a/src/hyperfine/timer/unix_timer.rs b/src/hyperfine/timer/unix_timer.rs index adfdc67..74e085d 100644 --- a/src/hyperfine/timer/unix_timer.rs +++ b/src/hyperfine/timer/unix_timer.rs @@ -50,6 +50,7 @@ fn get_cpu_times() -> CPUTimes { const MICROSEC_PER_SEC: i64 = 1000 * 1000; + #[allow(clippy::useless_conversion)] CPUTimes { user_usec: i64::from(result.ru_utime.tv_sec) * MICROSEC_PER_SEC + i64::from(result.ru_utime.tv_usec), diff --git a/src/hyperfine/types.rs b/src/hyperfine/types.rs index e5f863f..93624a0 100644 --- a/src/hyperfine/types.rs +++ b/src/hyperfine/types.rs @@ -30,15 +30,15 @@ impl fmt::Display for NumericType { } } -impl Into for i32 { - fn into(self) -> NumericType { - NumericType::Int(self) +impl From for NumericType { + fn from(x: i32) -> NumericType { + NumericType::Int(x) } } -impl Into for Decimal { - fn into(self) -> NumericType { - NumericType::Decimal(self) +impl From for NumericType { + fn from(x: Decimal) -> NumericType { + NumericType::Decimal(x) } } @@ -325,6 +325,7 @@ pub struct BenchmarkResult { impl BenchmarkResult { /// Create a new entry with the given values. + #[allow(clippy::too_many_arguments)] pub fn new( command: String, mean: Second, diff --git a/src/main.rs b/src/main.rs index f573a72..aeb4a04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,8 @@ fn build_hyperfine_options<'a>( matches .value_of(param) .map(|n| { - u64::from_str_radix(n, 10).map_err(|e| OptionsError::NumericParsingError(param, e)) + n.parse::() + .map_err(|e| OptionsError::NumericParsingError(param, e)) }) .transpose() }; @@ -270,7 +271,8 @@ fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec> { 'outer: loop { let name = command_names .get(i) - .or_else(|| command_names.get(0)).copied(); + .or_else(|| command_names.get(0)) + .copied(); i += 1; let (command_index, params_indices) = index.split_first().unwrap();