From 2e90c78fae96c5f4d29ce0242777c1f01d9aeae9 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 26 Dec 2019 11:12:33 -0600 Subject: [PATCH] refactor/polish ~ fix `cargo clippy` complaints (redundant closure) --- src/cp/cp.rs | 4 ++-- src/dircolors/dircolors.rs | 2 +- src/env/env.rs | 4 ++-- src/fmt/parasplit.rs | 4 ++-- src/fold/fold.rs | 2 +- src/install/install.rs | 2 +- src/ls/ls.rs | 4 ++-- src/shuf/shuf.rs | 4 ++-- src/stat/stat.rs | 4 ++-- src/stdbuf/stdbuf.rs | 2 +- src/users/users.rs | 2 +- src/who/who.rs | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index f63a73cd9..d04925808 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -475,7 +475,7 @@ pub fn uumain(args: Vec) -> i32 { let options = crash_if_err!(EXIT_ERR, Options::from_matches(&matches)); let paths: Vec = matches .values_of("paths") - .map(|v| v.map(|p| p.to_string()).collect()) + .map(|v| v.map(std::string::ToString::to_string).collect()) .unwrap_or_default(); let (sources, target) = crash_if_err!(EXIT_ERR, parse_path_args(&paths, &options)); @@ -590,7 +590,7 @@ impl Options { let no_target_dir = matches.is_present(OPT_NO_TARGET_DIRECTORY); let target_dir = matches .value_of(OPT_TARGET_DIRECTORY) - .map(|v| v.to_string()); + .map(std::string::ToString::to_string); // Parse attributes to preserve let preserve_attributes: Vec = if matches.is_present(OPT_PRESERVE) { diff --git a/src/dircolors/dircolors.rs b/src/dircolors/dircolors.rs index 864438500..31a065b06 100644 --- a/src/dircolors/dircolors.rs +++ b/src/dircolors/dircolors.rs @@ -120,7 +120,7 @@ pub fn uumain(args: Vec) -> i32 { Ok(f) => { let fin = BufReader::new(f); result = parse( - fin.lines().filter_map(|l| l.ok()), + fin.lines().filter_map(std::result::Result::ok), out_format, matches.free[0].as_str(), ) diff --git a/src/env/env.rs b/src/env/env.rs index 1d03137a4..a8c5344c0 100644 --- a/src/env/env.rs +++ b/src/env/env.rs @@ -159,11 +159,11 @@ fn run_env(args: Vec) -> Result<(), i32> { let null = matches.is_present("null"); let files = matches .values_of("file") - .map(|v| v.collect()) + .map(std::iter::Iterator::collect) .unwrap_or_else(|| Vec::with_capacity(0)); let unsets = matches .values_of("unset") - .map(|v| v.collect()) + .map(std::iter::Iterator::collect) .unwrap_or_else(|| Vec::with_capacity(0)); let mut opts = Options { diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index 43fcc42b6..de9734729 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -164,7 +164,7 @@ impl<'a> Iterator for FileLines<'a> { // emit a blank line // Err(true) indicates that this was a linebreak, // which is important to know when detecting mail headers - if n.chars().all(|c| c.is_whitespace()) { + if n.chars().all(char::is_whitespace) { return Some(Line::NoFormatLine("".to_owned(), true)); } @@ -180,7 +180,7 @@ impl<'a> Iterator for FileLines<'a> { // following line) n[poffset + self.opts.prefix.len()..] .chars() - .all(|c| c.is_whitespace()) + .all(char::is_whitespace) { return Some(Line::NoFormatLine(n, false)); } diff --git a/src/fold/fold.rs b/src/fold/fold.rs index 7ff9dd163..083dd8df6 100644 --- a/src/fold/fold.rs +++ b/src/fold/fold.rs @@ -110,7 +110,7 @@ fn fold_file(mut file: BufReader, bytes: bool, spaces: bool, width: let slice = { let slice = &line[i..i + width]; if spaces && i + width < len { - match slice.rfind(|ch: char| ch.is_whitespace()) { + match slice.rfind(char::is_whitespace) { Some(m) => &slice[..=m], None => slice, } diff --git a/src/install/install.rs b/src/install/install.rs index 7112811df..0ae97cf34 100644 --- a/src/install/install.rs +++ b/src/install/install.rs @@ -297,7 +297,7 @@ fn directory(paths: &[PathBuf], b: Behaviour) -> i32 { /// Test if the path is a a new file path that can be /// created immediately fn is_new_file_path(path: &Path) -> bool { - path.is_file() || !path.exists() && path.parent().map(|p| p.is_dir()).unwrap_or(true) + path.is_file() || !path.exists() && path.parent().map(std::path::Path::is_dir).unwrap_or(true) } /// Perform an install, given a list of paths and behaviour. diff --git a/src/ls/ls.rs b/src/ls/ls.rs index c1cc909a6..05f89d8c0 100644 --- a/src/ls/ls.rs +++ b/src/ls/ls.rs @@ -289,8 +289,8 @@ fn should_display(entry: &DirEntry, options: &getopts::Matches) -> bool { } fn enter_directory(dir: &PathBuf, options: &getopts::Matches) { - let mut entries = - safe_unwrap!(fs::read_dir(dir).and_then(|e| e.collect::, _>>())); + let mut entries: Vec<_> = + safe_unwrap!(fs::read_dir(dir).and_then(std::iter::Iterator::collect)); entries.retain(|e| should_display(e, options)); diff --git a/src/shuf/shuf.rs b/src/shuf/shuf.rs index aaf6280a8..70a685143 100644 --- a/src/shuf/shuf.rs +++ b/src/shuf/shuf.rs @@ -123,14 +123,14 @@ With no FILE, or when FILE is -, read standard input.", let mut evec = matches .free .iter() - .map(|a| a.as_bytes()) + .map(std::string::String::as_bytes) .collect::>(); find_seps(&mut evec, sep); shuf_bytes(&mut evec, repeat, count, sep, output, random); } Mode::InputRange((b, e)) => { let rvec = (b..e).map(|x| format!("{}", x)).collect::>(); - let mut rvec = rvec.iter().map(|a| a.as_bytes()).collect::>(); + let mut rvec = rvec.iter().map(std::string::String::as_bytes).collect::>(); shuf_bytes(&mut rvec, repeat, count, sep, output, random); } Mode::Default => { diff --git a/src/stat/stat.rs b/src/stat/stat.rs index caef583e0..4d96f1e98 100644 --- a/src/stat/stat.rs +++ b/src/stat/stat.rs @@ -482,8 +482,8 @@ impl Stater { ); let mut mount_list = reader .lines() - .filter_map(|s| s.ok()) - .filter_map(|line| line.split_whitespace().nth(1).map(|s| s.to_owned())) + .filter_map(std::result::Result::ok) + .filter_map(|line| line.split_whitespace().nth(1).map(std::borrow::ToOwned::to_owned)) .collect::>(); // Reverse sort. The longer comes first. mount_list.sort_by(|a, b| b.cmp(a)); diff --git a/src/stdbuf/stdbuf.rs b/src/stdbuf/stdbuf.rs index 7932fdd45..6920a1ae9 100644 --- a/src/stdbuf/stdbuf.rs +++ b/src/stdbuf/stdbuf.rs @@ -94,7 +94,7 @@ fn print_usage(opts: &Options) { fn parse_size(size: &str) -> Option { let ext = size.trim_start_matches(|c: char| c.is_digit(10)); - let num = size.trim_end_matches(|c: char| c.is_alphabetic()); + let num = size.trim_end_matches(char::is_alphabetic); let mut recovered = num.to_owned(); recovered.push_str(ext); if recovered != size { diff --git a/src/users/users.rs b/src/users/users.rs index dae2f3a20..11330346e 100644 --- a/src/users/users.rs +++ b/src/users/users.rs @@ -67,7 +67,7 @@ pub fn uumain(args: Vec) -> i32 { fn exec(filename: &str) { let mut users = Utmpx::iter_all_records() .read_from(filename) - .filter(|ut| ut.is_user_process()) + .filter(uucore::utmpx::Utmpx::is_user_process) .map(|ut| ut.user()) .collect::>(); diff --git a/src/who/who.rs b/src/who/who.rs index 18fb862d4..73277fe5b 100644 --- a/src/who/who.rs +++ b/src/who/who.rs @@ -311,7 +311,7 @@ impl Who { if self.short_list { let users = Utmpx::iter_all_records() .read_from(f) - .filter(|ut| ut.is_user_process()) + .filter(uucore::utmpx::Utmpx::is_user_process) .map(|ut| ut.user()) .collect::>(); println!("{}", users.join(" "));