1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

apply more clippy suggestions from nightly

This commit is contained in:
Reto Hablützel 2021-04-12 20:07:10 +02:00
parent 07e9c5896c
commit a4253d1254
7 changed files with 14 additions and 31 deletions

View file

@ -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;
}

View file

@ -78,7 +78,7 @@ fn detect_algo<'a>(
"sha512sum" => ("SHA512", Box::new(Sha512::new()) as Box<dyn Digest>, 512),
"b2sum" => ("BLAKE2", Box::new(Blake2b::new(64)) as Box<dyn Digest>, 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::<usize>() {
Ok(224) => (
"SHA3-224",
Box::new(Sha3_224::new()) as Box<dyn Digest>,
@ -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::<usize>() {
Ok(bits) => (
"SHAKE128",
Box::new(Shake128::new()) as Box<dyn Digest>,
@ -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::<usize>() {
Ok(bits) => (
"SHAKE256",
Box::new(Shake256::new()) as Box<dyn Digest>,
@ -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::<usize>() {
Ok(224) => set_or_crash(
"SHA3-224",
Box::new(Sha3_224::new()) as Box<dyn Digest>,
@ -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::<usize>() {
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::<usize>() {
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, ParseIntError> {
usize::from_str_radix(arg, 10)
arg.parse()
}
fn is_valid_bit_num(arg: String) -> Result<(), String> {

View file

@ -263,9 +263,5 @@ pub fn num_format(field: &FormatField, in_str_opt: Option<&String>) -> Option<St
};
// if we have a formatPrimitive, print its results
// according to the field-char appropriate Formatter
if let Some(prim) = prim_opt {
Some(fmtr.primitive_to_str(&prim, field.clone()))
} else {
None
}
prim_opt.map(|prim| fmtr.primitive_to_str(&prim, field.clone()))
}

View file

@ -177,14 +177,14 @@ fn get_config(matches: &clap::ArgMatches) -> 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::<usize>());
}
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::<usize>());
}
if matches.is_present(options::FORMAT_ROFF) {
config.format = OutFormat::Roff;

View file

@ -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);

View file

@ -149,10 +149,8 @@ fn next_tabstop(tabstops: &[usize], col: usize) -> Option<usize> {
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)
}
}

View file

@ -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<String>,
}
@ -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()