1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

address some new clippy warnings (#1642)

This commit is contained in:
Sylvestre Ledru 2020-11-29 16:26:38 +01:00 committed by GitHub
parent df44534a3e
commit 8ef7f394c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 28 additions and 45 deletions

View file

@ -17,7 +17,6 @@ use uucore::libc::{self, chroot, setgid, setgroups, setuid};
use std::ffi::CString;
use std::io::Error;
use std::iter::FromIterator;
use std::path::Path;
use std::process::Command;
@ -96,10 +95,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if pstatus.success() {
0
} else {
match pstatus.code() {
Some(i) => i,
None => -1,
}
pstatus.code().unwrap_or(-1)
}
}
@ -182,11 +178,13 @@ fn set_groups(groups: Vec<libc::gid_t>) -> libc::c_int {
fn set_groups_from_str(groups: &str) {
if !groups.is_empty() {
let groups_vec: Vec<libc::gid_t> =
FromIterator::from_iter(groups.split(',').map(|x| match entries::grp2gid(x) {
let groups_vec: Vec<libc::gid_t> = groups
.split(',')
.map(|x| match entries::grp2gid(x) {
Ok(g) => g,
_ => crash!(1, "no such group: {}", x),
}));
})
.collect();
let err = set_groups(groups_vec);
if err != 0 {
crash!(1, "cannot set groups: {}", Error::last_os_error())

View file

@ -41,7 +41,7 @@ fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
fn ensure_nl(line: &mut String) {
match line.chars().last() {
Some('\n') => (),
_ => line.push_str("\n"),
_ => line.push('\n'),
}
}

View file

@ -41,7 +41,7 @@ fn process_expr(token_strings: &[String]) -> Result<String, String> {
fn print_expr_ok(expr_result: &str) -> i32 {
println!("{}", expr_result);
if expr_result == "0" || expr_result == "" {
if expr_result == "0" || expr_result.is_empty() {
1
} else {
0

View file

@ -696,10 +696,7 @@ fn get_field_number(keys: Option<usize>, key: Option<usize>) -> usize {
return keys;
}
match key {
Some(key) => key,
None => 0,
}
key.unwrap_or(0)
}
/// Parse the specified field string as a natural number and return

View file

@ -85,7 +85,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
_ => crash!(1, "no mode given"),
}
}
_ => 0o755 as u16,
_ => 0o755_u16,
};
exec(dirs, recursive, mode, verbose)

View file

@ -96,7 +96,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let (prefix, rand, suffix) = match parse_template(template) {
Some((p, r, s)) => match suffix_opt {
Some(suf) => {
if s == "" {
if s.is_empty() {
(p, r, suf)
} else {
crash!(

View file

@ -103,7 +103,7 @@ process).",
println!("{}", niceness);
return 0;
}
10 as c_int
10_i32
}
};

View file

@ -310,7 +310,7 @@ fn nl<T: Read>(reader: &mut BufReader<T>, settings: &Settings) {
continue;
}
// From this point on we format and print a "regular" line.
if line == "" {
if line.is_empty() {
// The line is empty, which means that we have to care
// about the --join-blank-lines parameter.
empty_line_count += 1;

View file

@ -73,10 +73,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if !matches.is_present(OPT_ALL) {
// OMP_NUM_THREADS doesn't have an impact on --all
ignore += match env::var("OMP_NUM_THREADS") {
Ok(threadstr) => match threadstr.parse() {
Ok(num) => num,
Err(_) => 0,
},
Ok(threadstr) => threadstr.parse().unwrap_or(0),
Err(_) => 0,
};
}

View file

@ -229,10 +229,7 @@ impl OdOptions {
let mut line_bytes = match matches.opt_default("w", "32") {
None => 16,
Some(s) => match s.parse::<usize>() {
Ok(i) => i,
Err(_) => 0,
},
Some(s) => s.parse::<usize>().unwrap_or(0),
};
let min_bytes = formats.iter().fold(1, |max, next| {
cmp::max(max, next.formatter_item_info.byte_size)

View file

@ -64,7 +64,7 @@ fn get_provided(str_in_opt: Option<&String>) -> Option<u8> {
None => {
let so_far = (qchar as u8 as char).to_string();
warn_expected_numeric(&so_far);
0 as u8
0_u8
}
})
}
@ -72,7 +72,7 @@ fn get_provided(str_in_opt: Option<&String>) -> Option<u8> {
_ => None, // no first byte
}
} else {
Some(0 as u8)
Some(0_u8)
}
}
None => Some(0),

View file

@ -85,10 +85,7 @@ impl UnescapedText {
// to the passed byte_vec
// in subs_mode change octal behavior
fn handle_escaped(byte_vec: &mut Vec<u8>, it: &mut PutBackN<Chars>, subs_mode: bool) {
let ch = match it.next() {
Some(x) => x,
None => '\\',
};
let ch = it.next().unwrap_or('\\');
match ch {
'0'..='9' | 'x' => {
let min_len = 1;

View file

@ -478,10 +478,7 @@ fn numeric_compare(a: &str, b: &str) -> Ordering {
fn human_numeric_convert(a: &str) -> f64 {
let int_str: String = a.chars().take_while(|c| c.is_numeric()).collect();
let suffix = a.chars().find(|c| !c.is_numeric());
let int_part = match int_str.parse::<f64>() {
Ok(i) => i,
Err(_) => -1f64,
} as f64;
let int_part = int_str.parse::<f64>().unwrap_or(-1f64) as f64;
let suffix: f64 = match suffix.unwrap_or('\0') {
'K' => 1000f64,
'M' => 1E6,

View file

@ -469,7 +469,7 @@ impl Stater {
let fmtstr = if matches.is_present(OPT_PRINTF) {
matches.value_of(OPT_PRINTF).expect("Invalid format string")
} else {
matches.value_of(OPT_FORMAT).unwrap_or_else(|| "")
matches.value_of(OPT_FORMAT).unwrap_or("")
};
let use_printf = matches.is_present(OPT_PRINTF);

View file

@ -111,28 +111,28 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
if kernelname || all || none {
output.push_str(&uname.sysname());
output.push_str(" ");
output.push(' ');
}
if nodename || all {
output.push_str(&uname.nodename());
output.push_str(" ");
output.push(' ');
}
if kernelrelease || all {
output.push_str(&uname.release());
output.push_str(" ");
output.push(' ');
}
if kernelversion || all {
output.push_str(&uname.version());
output.push_str(" ");
output.push(' ');
}
if machine || all {
output.push_str(&uname.machine());
output.push_str(" ");
output.push(' ');
}
if os || all {
output.push_str(HOST_OS);
output.push_str(" ");
output.push(' ');
}
println!("{}", output.trim_end());

View file

@ -148,8 +148,8 @@ const CR: u8 = b'\r';
const LF: u8 = b'\n';
const SPACE: u8 = b' ';
const TAB: u8 = b'\t';
const SYN: u8 = 0x16 as u8;
const FF: u8 = 0x0C as u8;
const SYN: u8 = 0x16_u8;
const FF: u8 = 0x0C_u8;
#[inline(always)]
fn is_word_separator(byte: u8) -> bool {