clippy cleanup

This commit is contained in:
Lynne Megido 2022-09-04 13:48:54 +10:00
parent 420bd0483c
commit acd33980e9
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
3 changed files with 13 additions and 12 deletions

View file

@ -14,9 +14,9 @@ fn main() -> Result<(), String> {
// a more robust way of doing this would be to use vergen (https://github.com/rustyhorde/vergen), but it pulls in a // a more robust way of doing this would be to use vergen (https://github.com/rustyhorde/vergen), but it pulls in a
// whole bunch of extra dependencies (including chrono and git2), and also blocks compilation on the current MSRV. // whole bunch of extra dependencies (including chrono and git2), and also blocks compilation on the current MSRV.
// this method is less clever and robust, but it works! // this method is less clever and robust, but it works!
let git = Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output(); let git = Command::new("git").args(["rev-parse", "--short", "HEAD"]).output();
let hash = match git { let hash = match git {
Ok(output) => String::from_utf8_lossy(&*output.stdout).into(), Ok(output) => String::from_utf8_lossy(&output.stdout).into(),
Err(_) => { Err(_) => {
// git not being present (or failing) shouldn't block compilation // git not being present (or failing) shouldn't block compilation
println!("cargo:warning=Failed to retrieve git commit hash"); println!("cargo:warning=Failed to retrieve git commit hash");

View file

@ -163,10 +163,10 @@ fn main() {
// handles: --prompt never --overwrite // handles: --prompt never --overwrite
// user specified --prompt never in conjunction with --overwrite, so always rename // user specified --prompt never in conjunction with --overwrite, so always rename
true true
} else if prompt == Prompt::Error || ask(&*format!("Rename {:#?} to {:#?}?", &f.file, &rename_to)) { } else if prompt == Prompt::Error || ask(&format!("Rename {:#?} to {:#?}?", &f.file, &rename_to)) {
// handles: --prompt error --overwrite, --prompt always --overwrite [y] // handles: --prompt error --overwrite, --prompt always --overwrite [y]
// if the target exists, prompt before renaming; otherwise, just rename // if the target exists, prompt before renaming; otherwise, just rename
!rename_to.exists() || ask(&*format!("Destination {:#?} already exists, overwrite?", rename_to)) !rename_to.exists() || ask(&format!("Destination {:#?} already exists, overwrite?", rename_to))
} else { } else {
// handles: --prompt always --overwrite [n] // handles: --prompt always --overwrite [n]
// user was prompted and replied "no" // user was prompted and replied "no"
@ -191,7 +191,7 @@ fn main() {
warn!("Couldn't rename {:#?} to {:#?}: {:#?}", f.file, rename_to, e); warn!("Couldn't rename {:#?} to {:#?}: {:#?}", f.file, rename_to, e);
// if the user passed --prompt never, continue to the next file // if the user passed --prompt never, continue to the next file
// otherwise, prompt user to retry move, retrying until the rename succeeds or they respond "N" // otherwise, prompt user to retry move, retrying until the rename succeeds or they respond "N"
if prompt == Prompt::Never || !ask(&*format!("Error while renaming file: {:#?}. Try again?", e)) { if prompt == Prompt::Never || !ask(&format!("Error while renaming file: {:#?}. Try again?", e)) {
failed += 1; failed += 1;
break; break;
} }

View file

@ -102,11 +102,12 @@ fn simple_directory() {
set_current_dir(dir.path()).expect("Failed to change directory."); set_current_dir(dir.path()).expect("Failed to change directory.");
for (name, bytes) in &files { for (name, bytes) in &files {
let mut file = File::create(dir.path().join(name)).expect(&*format!("Failed to create file: {}", name)); let mut file = File::create(dir.path().join(name))
.unwrap_or_else(|_| panic!("Failed to create file: {}", name));
file file
.write_all(bytes) .write_all(bytes)
.expect(&*format!("Failed to write to file: {}", name)); .unwrap_or_else(|_| panic!("Failed to write to file: {}", name));
drop(file); drop(file);
} }
@ -225,7 +226,7 @@ fn argument_parsing() {
#[test] #[test]
/// Ensure that `fif -e jpg dir` is interpreted as "scan for jpg files in dir" and not "scan for jpg and dir files" /// Ensure that `fif -e jpg dir` is interpreted as "scan for jpg files in dir" and not "scan for jpg and dir files"
fn positional_args() { fn positional_args() {
for flag in &["-x", "-e", "-X", "-E"] { for flag in ["-x", "-e", "-X", "-E"] {
assert_eq!( assert_eq!(
Parameters::parse_from(vec!["fif", flag, "images", "directory"]).dir, Parameters::parse_from(vec!["fif", flag, "images", "directory"]).dir,
PathBuf::from("directory") PathBuf::from("directory")
@ -483,8 +484,8 @@ fn media_contains_audio_video_images() {
.for_each(|ext| assert!(media_exts.contains(&ext))); .for_each(|ext| assert!(media_exts.contains(&ext)));
assert_eq!( assert_eq!(
Parameters::parse_from(&["fif", "-E", "media"]).extensions(), Parameters::parse_from(["fif", "-E", "media"]).extensions(),
Parameters::parse_from(&["fif", "-E", "audio,video,images"]).extensions() Parameters::parse_from(["fif", "-E", "audio,video,images"]).extensions()
); );
} }
@ -510,7 +511,7 @@ fn writables_is_correct() {
fn verbosity() { fn verbosity() {
use log::LevelFilter; use log::LevelFilter;
assert!( assert!(
Parameters::try_parse_from(&["fif", "-q", "-v"]).is_err(), Parameters::try_parse_from(["fif", "-q", "-v"]).is_err(),
"Failed to reject usage of both -q and -v!" "Failed to reject usage of both -q and -v!"
); );
@ -527,7 +528,7 @@ fn verbosity() {
]; ];
for (flags, level) in expected_results { for (flags, level) in expected_results {
assert_eq!(Parameters::parse_from(&["fif", flags]).get_verbosity(), level); assert_eq!(Parameters::parse_from(["fif", flags]).get_verbosity(), level);
} }
} }