refactor/polish ~ fix cargo clippy complaints (default/tests => let ... = if ...)

This commit is contained in:
Roy Ivy III 2019-12-26 17:02:55 -06:00
parent d192ebea5b
commit 8142ecf325
4 changed files with 16 additions and 24 deletions

View file

@ -333,10 +333,9 @@ fn nl<T: Read>(reader: &mut BufReader<T>, settings: &Settings) {
// way, start counting empties from zero once more. // way, start counting empties from zero once more.
empty_line_count = 0; empty_line_count = 0;
// A line number is to be printed. // A line number is to be printed.
let mut w: usize = 0; let w = if settings.number_width > line_no_width {
if settings.number_width > line_no_width { settings.number_width - line_no_width
w = settings.number_width - line_no_width; } else { 0 };
}
let fill: String = repeat(fill_char).take(w).collect(); let fill: String = repeat(fill_char).take(w).collect();
match settings.number_format { match settings.number_format {
NumberFormat::Left => println!( NumberFormat::Left => println!(

View file

@ -86,11 +86,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
0 0
} }
_ => { _ => {
let mut res = true; let mut res = if matches.free.is_empty() {
if matches.free.len() == 0 {
show_error!("missing operand\nTry {} --help for more information", NAME); show_error!("missing operand\nTry {} --help for more information", NAME);
res = false; false
} } else { true };
// free strings are path operands // free strings are path operands
// FIXME: TCS, seems inefficient and overly verbose (?) // FIXME: TCS, seems inefficient and overly verbose (?)
for p in matches.free { for p in matches.free {

View file

@ -60,11 +60,10 @@ impl UnescapedText {
// dropped-in as a replacement. // dropped-in as a replacement.
fn validate_iec(val: u32, eight_word: bool) { fn validate_iec(val: u32, eight_word: bool) {
let mut preface = 'u'; let mut preface = 'u';
let mut leading_zeros = 4; let leading_zeros = if eight_word {
if eight_word {
preface = 'U'; preface = 'U';
leading_zeros = 8; 8
} } else { 4 };
let err_msg = format!( let err_msg = format!(
"invalid universal character name {0}{1:02$x}", "invalid universal character name {0}{1:02$x}",
preface, val, leading_zeros preface, val, leading_zeros

View file

@ -70,18 +70,13 @@ pub fn uumain(args: Vec<String>) -> i32 {
let silent = matches.opt_present("silent") || matches.opt_present("quiet"); let silent = matches.opt_present("silent") || matches.opt_present("quiet");
let verbose = matches.opt_present("verbose"); let verbose = matches.opt_present("verbose");
let mut can_mode = CanonicalizeMode::None; let can_mode = if matches.opt_present("canonicalize") {
if matches.opt_present("canonicalize") { CanonicalizeMode::Normal
can_mode = CanonicalizeMode::Normal; } else if matches.opt_present("canonicalize-existing") {
} CanonicalizeMode::Existing
} else if matches.opt_present("canonicalize-missing") {
if matches.opt_present("canonicalize-existing") { CanonicalizeMode::Missing
can_mode = CanonicalizeMode::Existing; } else { CanonicalizeMode::None };
}
if matches.opt_present("canonicalize-missing") {
can_mode = CanonicalizeMode::Missing;
}
let files = matches.free; let files = matches.free;
if files.is_empty() { if files.is_empty() {