From a4253d125497a98e15f4da27191053302a1870e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reto=20Habl=C3=BCtzel?= Date: Mon, 12 Apr 2021 20:07:10 +0200 Subject: [PATCH] apply more clippy suggestions from nightly --- src/uu/df/src/df.rs | 5 ----- src/uu/hashsum/src/hashsum.rs | 14 +++++++------- .../printf/src/tokenize/num_format/num_format.rs | 6 +----- src/uu/ptx/src/ptx.rs | 4 ++-- src/uu/shred/src/shred.rs | 5 +---- src/uu/unexpand/src/unexpand.rs | 6 ++---- src/uu/who/src/who.rs | 5 +---- 7 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 57caf7970..e898b187c 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -116,7 +116,6 @@ struct Options { show_listed_fs: bool, show_fs_type: bool, show_inode_instead: bool, - print_grand_total: bool, // block_size: usize, human_readable_base: i64, fs_selector: FsSelector, @@ -286,7 +285,6 @@ impl Options { show_listed_fs: false, show_fs_type: false, show_inode_instead: false, - print_grand_total: false, // block_size: match env::var("BLOCKSIZE") { // Ok(size) => size.parse().unwrap(), // Err(_) => 512, @@ -871,9 +869,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if matches.is_present(OPT_ALL) { opt.show_all_fs = true; } - if matches.is_present(OPT_TOTAL) { - opt.print_grand_total = true; - } if matches.is_present(OPT_INODES) { opt.show_inode_instead = true; } diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index ee7d2a0f7..2e31ddd25 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -78,7 +78,7 @@ fn detect_algo<'a>( "sha512sum" => ("SHA512", Box::new(Sha512::new()) as Box, 512), "b2sum" => ("BLAKE2", Box::new(Blake2b::new(64)) as Box, 512), "sha3sum" => match matches.value_of("bits") { - Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { + Some(bits_str) => match (&bits_str).parse::() { Ok(224) => ( "SHA3-224", Box::new(Sha3_224::new()) as Box, @@ -128,7 +128,7 @@ fn detect_algo<'a>( 512, ), "shake128sum" => match matches.value_of("bits") { - Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { + Some(bits_str) => match (&bits_str).parse::() { Ok(bits) => ( "SHAKE128", Box::new(Shake128::new()) as Box, @@ -139,7 +139,7 @@ fn detect_algo<'a>( None => crash!(1, "--bits required for SHAKE-128"), }, "shake256sum" => match matches.value_of("bits") { - Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { + Some(bits_str) => match (&bits_str).parse::() { Ok(bits) => ( "SHAKE256", Box::new(Shake256::new()) as Box, @@ -182,7 +182,7 @@ fn detect_algo<'a>( } if matches.is_present("sha3") { match matches.value_of("bits") { - Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { + Some(bits_str) => match (&bits_str).parse::() { Ok(224) => set_or_crash( "SHA3-224", Box::new(Sha3_224::new()) as Box, @@ -226,7 +226,7 @@ fn detect_algo<'a>( } if matches.is_present("shake128") { match matches.value_of("bits") { - Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { + Some(bits_str) => match (&bits_str).parse::() { Ok(bits) => set_or_crash("SHAKE128", Box::new(Shake128::new()), bits), Err(err) => crash!(1, "{}", err), }, @@ -235,7 +235,7 @@ fn detect_algo<'a>( } if matches.is_present("shake256") { match matches.value_of("bits") { - Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { + Some(bits_str) => match (&bits_str).parse::() { Ok(bits) => set_or_crash("SHAKE256", Box::new(Shake256::new()), bits), Err(err) => crash!(1, "{}", err), }, @@ -253,7 +253,7 @@ fn detect_algo<'a>( // TODO: return custom error type fn parse_bit_num(arg: &str) -> Result { - usize::from_str_radix(arg, 10) + arg.parse() } fn is_valid_bit_num(arg: String) -> Result<(), String> { diff --git a/src/uu/printf/src/tokenize/num_format/num_format.rs b/src/uu/printf/src/tokenize/num_format/num_format.rs index 9a519e95e..812f51b5a 100644 --- a/src/uu/printf/src/tokenize/num_format/num_format.rs +++ b/src/uu/printf/src/tokenize/num_format/num_format.rs @@ -263,9 +263,5 @@ pub fn num_format(field: &FormatField, in_str_opt: Option<&String>) -> Option Config { } if matches.is_present(options::WIDTH) { let width_str = matches.value_of(options::WIDTH).expect(err_msg).to_string(); - config.line_width = crash_if_err!(1, usize::from_str_radix(&width_str, 10)); + config.line_width = crash_if_err!(1, (&width_str).parse::()); } if matches.is_present(options::GAP_SIZE) { let gap_str = matches .value_of(options::GAP_SIZE) .expect(err_msg) .to_string(); - config.gap_size = crash_if_err!(1, usize::from_str_radix(&gap_str, 10)); + config.gap_size = crash_if_err!(1, (&gap_str).parse::()); } if matches.is_present(options::FORMAT_ROFF) { config.format = OutFormat::Roff; diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index c56f14280..b89d48a10 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -363,10 +363,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let force = matches.is_present(options::FORCE); let remove = matches.is_present(options::REMOVE); - let size_arg = match matches.value_of(options::SIZE) { - Some(s) => Some(s.to_string()), - None => None, - }; + let size_arg = matches.value_of(options::SIZE).map(|s| s.to_string()); let size = get_size(size_arg); let exact = matches.is_present(options::EXACT) && size.is_none(); // if -s is given, ignore -x let zero = matches.is_present(options::ZERO); diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 5b08c33cf..3d80bd6e9 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -149,10 +149,8 @@ fn next_tabstop(tabstops: &[usize], col: usize) -> Option { Some(tabstops[0] - col % tabstops[0]) } else { // find next larger tab - match tabstops.iter().find(|&&t| t > col) { - Some(t) => Some(t - col), - None => None, // if there isn't one in the list, tab becomes a single space - } + // if there isn't one in the list, tab becomes a single space + tabstops.iter().find(|&&t| t > col).map(|t| t-col) } } diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 8c7ff3211..9444985dc 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -222,7 +222,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 { need_runlevel, need_users, my_line_only, - has_records: false, args: matches.free, }; @@ -247,7 +246,6 @@ struct Who { need_runlevel: bool, need_users: bool, my_line_only: bool, - has_records: bool, args: Vec, } @@ -321,8 +319,7 @@ impl Who { println!("{}", users.join(" ")); println!("# users={}", users.len()); } else { - let mut records = Utmpx::iter_all_records().read_from(f).peekable(); - self.has_records = records.peek().is_some(); + let records = Utmpx::iter_all_records().read_from(f).peekable(); if self.include_heading { self.print_heading()