1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-04 15:07:47 +00:00

refactor/polish ~ fix cargo clippy complaints (collapse else-if)

This commit is contained in:
Roy Ivy III 2019-12-26 15:40:17 -06:00
parent 2db6fb20c9
commit b8eb763e43
8 changed files with 26 additions and 42 deletions

View file

@ -202,12 +202,10 @@ fn determine_backup_suffix(backup_mode: BackupMode, matches: &getopts::Matches)
); );
} }
} }
} else if let (Ok(s), BackupMode::SimpleBackup) = (env::var("SIMPLE_BACKUP_SUFFIX"), backup_mode) {
s
} else { } else {
if let (Ok(s), BackupMode::SimpleBackup) = (env::var("SIMPLE_BACKUP_SUFFIX"), backup_mode) { "~".to_owned()
s
} else {
"~".to_owned()
}
} }
} }

View file

@ -115,12 +115,10 @@ fn num_cpus_all() -> usize {
// In some situation, /proc and /sys are not mounted, and sysconf returns 1. // In some situation, /proc and /sys are not mounted, and sysconf returns 1.
// However, we want to guarantee that `nproc --all` >= `nproc`. // However, we want to guarantee that `nproc --all` >= `nproc`.
num_cpus::get() num_cpus::get()
} else if nprocs > 0 {
nprocs as usize
} else { } else {
if nprocs > 0 { 1
nprocs as usize
} else {
1
}
} }
} }

View file

@ -290,10 +290,8 @@ impl Pinky {
if ut.is_user_process() { if ut.is_user_process() {
if self.names.is_empty() { if self.names.is_empty() {
self.print_entry(&ut) self.print_entry(&ut)
} else { } else if self.names.iter().any(|n| n.as_str() == ut.user()) {
if self.names.iter().any(|n| n.as_str() == ut.user()) {
self.print_entry(&ut); self.print_entry(&ut);
}
} }
} }
} }

View file

@ -27,12 +27,10 @@ fn has_enough_digits(
} else { } else {
false //undecidable without converting false //undecidable without converting
} }
} else { } else if hex_input {
if hex_input {
((((string_position - 1) - starting_position) * 9) / 8 >= limit) ((((string_position - 1) - starting_position) * 9) / 8 >= limit)
} else { } else {
((string_position - 1) - starting_position >= limit) ((string_position - 1) - starting_position >= limit)
}
} }
} }

View file

@ -189,14 +189,12 @@ fn read_input(input_files: &[String], config: &Config) -> HashMap<String, (Vec<S
let mut files = Vec::new(); let mut files = Vec::new();
if input_files.is_empty() { if input_files.is_empty() {
files.push("-"); files.push("-");
} else { } else if config.gnu_ext {
if config.gnu_ext { for file in input_files {
for file in input_files { files.push(&file);
files.push(&file);
}
} else {
files.push(&input_files[0]);
} }
} else {
files.push(&input_files[0]);
} }
let mut lines_so_far: usize = 0; let mut lines_so_far: usize = 0;
for filename in files { for filename in files {

View file

@ -225,17 +225,15 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
} }
} else if options.dir && (!is_root || !options.preserve_root) { } else if options.dir && (!is_root || !options.preserve_root) {
had_err = remove_dir(path, options).bitor(had_err); had_err = remove_dir(path, options).bitor(had_err);
} else if options.recursive {
show_error!("could not remove directory '{}'", path.display());
had_err = true;
} else { } else {
if options.recursive { show_error!(
show_error!("could not remove directory '{}'", path.display()); "could not remove directory '{}' (did you mean to pass '-r'?)",
had_err = true; path.display()
} else { );
show_error!( had_err = true;
"could not remove directory '{}' (did you mean to pass '-r'?)",
path.display()
);
had_err = true;
}
} }
had_err had_err

View file

@ -302,12 +302,10 @@ fn exec(files: Vec<String>, settings: &Settings) -> i32 {
} else { } else {
print_sorted(file_merger, &settings.outfile) print_sorted(file_merger, &settings.outfile)
} }
} else if settings.unique {
print_sorted(lines.iter().dedup(), &settings.outfile)
} else { } else {
if settings.unique { print_sorted(lines.iter(), &settings.outfile)
print_sorted(lines.iter().dedup(), &settings.outfile)
} else {
print_sorted(lines.iter(), &settings.outfile)
}
} }
0 0

View file

@ -182,10 +182,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
if let Err(e) = set_symlink_file_times(path, atime, mtime) { if let Err(e) = set_symlink_file_times(path, atime, mtime) {
show_warning!("cannot touch '{}': {}", path, e); show_warning!("cannot touch '{}': {}", path, e);
} }
} else { } else if let Err(e) = filetime::set_file_times(path, atime, mtime) {
if let Err(e) = filetime::set_file_times(path, atime, mtime) {
show_warning!("cannot touch '{}': {}", path, e); show_warning!("cannot touch '{}': {}", path, e);
}
} }
} }