From f5de5487cc5be00d8833350eec82a78110a43aaa Mon Sep 17 00:00:00 2001 From: David Peter Date: Sat, 5 Feb 2022 22:14:06 +0100 Subject: [PATCH] Fix clippy suggestions --- .github/workflows/CICD.yml | 2 +- README.md | 2 +- src/error.rs | 2 +- src/export/asciidoc.rs | 8 +++----- src/export/markdown.rs | 8 +++----- src/main.rs | 2 +- src/options.rs | 30 +++++++++++++----------------- 7 files changed, 23 insertions(+), 31 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index c551113..3c28829 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1,7 +1,7 @@ name: CICD env: - MIN_SUPPORTED_RUST_VERSION: "1.54.0" + MIN_SUPPORTED_RUST_VERSION: "1.57.0" CICD_INTERMEDIATES_DIR: "_cicd-intermediates" on: diff --git a/README.md b/README.md index c9f5f39..8c4de96 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ Hyperfine can be installed from source via [cargo](https://doc.rust-lang.org/car cargo install hyperfine ``` -Make sure that you use Rust 1.54 or higher. +Make sure that you use Rust 1.57 or higher. ### From binaries (Linux, macOS, Windows) diff --git a/src/error.rs b/src/error.rs index 8e892db..279f337 100644 --- a/src/error.rs +++ b/src/error.rs @@ -55,7 +55,7 @@ impl fmt::Display for ParameterScanError { impl Error for ParameterScanError {} -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum OptionsError<'a> { EmptyRunsRange, TooManyCommandNames(usize), diff --git a/src/export/asciidoc.rs b/src/export/asciidoc.rs index 9a3d0d1..24269f7 100644 --- a/src/export/asciidoc.rs +++ b/src/export/asciidoc.rs @@ -74,12 +74,10 @@ fn table_row(entry: &BenchmarkResultWithRelativeSpeed, unit: Unit) -> Vec { let rel_str = format!("{:.2}", entry.relative_speed); let rel_stddev_str = if entry.is_fastest { "".into() + } else if let Some(stddev) = entry.relative_speed_stddev { + format!(" ± {:.2}", stddev) } else { - if let Some(stddev) = entry.relative_speed_stddev { - format!(" ± {:.2}", stddev) - } else { - "".into() - } + "".into() }; format!( diff --git a/src/export/markdown.rs b/src/export/markdown.rs index 0999767..ea4cc48 100644 --- a/src/export/markdown.rs +++ b/src/export/markdown.rs @@ -63,12 +63,10 @@ fn add_table_row(dest: &mut Vec, entry: &BenchmarkResultWithRelativeSpeed, u let rel_str = format!("{:.2}", entry.relative_speed); let rel_stddev_str = if entry.is_fastest { "".into() + } else if let Some(stddev) = entry.relative_speed_stddev { + format!(" ± {:.2}", stddev) } else { - if let Some(stddev) = entry.relative_speed_stddev { - format!(" ± {:.2}", stddev) - } else { - "".into() - } + "".into() }; dest.extend( diff --git a/src/main.rs b/src/main.rs index 3c4b35f..cf45f3f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -261,7 +261,7 @@ fn build_export_manager(matches: &ArgMatches) -> io::Result { } /// Build the commands to benchmark -fn build_commands<'a>(matches: &'a ArgMatches) -> Vec> { +fn build_commands(matches: &ArgMatches) -> Vec { let command_names = matches.values_of("command-name"); let command_strings = matches.values_of("command").unwrap(); diff --git a/src/options.rs b/src/options.rs index 3f933dd..4906b4f 100644 --- a/src/options.rs +++ b/src/options.rs @@ -182,25 +182,21 @@ fn test_shell_parse_command() { assert_eq!(&s, "shell -x 'aaa bbb'"); let cmd = shell.command(); - // Command::get_program and Command::args are not yet available in stable channel. - // https://doc.rust-lang.org/std/process/struct.Command.html#method.get_program - let s = format!("{:?}", cmd); - assert_eq!(&s, r#""shell" "-x" "aaa bbb""#); + assert_eq!(cmd.get_program().to_string_lossy(), "shell"); + assert_eq!( + cmd.get_args() + .map(|a| a.to_string_lossy()) + .collect::>(), + vec!["-x", "aaa bbb"] + ); // Error cases + assert!(matches!( + Shell::parse("shell 'foo").unwrap_err(), + OptionsError::ShellParseError(_) + )); - match Shell::parse("shell 'foo").unwrap_err() { - OptionsError::ShellParseError(_) => { /* ok */ } - e => assert!(false, "Unexpected error: {}", e), - } + assert_eq!(Shell::parse("").unwrap_err(), OptionsError::EmptyShell); - match Shell::parse("").unwrap_err() { - OptionsError::EmptyShell => { /* ok */ } - e => assert!(false, "Unexpected error: {}", e), - } - - match Shell::parse("''").unwrap_err() { - OptionsError::EmptyShell => { /* ok */ } - e => assert!(false, "Unexpected error: {}", e), - } + assert_eq!(Shell::parse("''").unwrap_err(), OptionsError::EmptyShell); }