diff --git a/src/cut/ranges.rs b/src/cut/ranges.rs index 44edcb943..76caff9ce 100644 --- a/src/cut/ranges.rs +++ b/src/cut/ranges.rs @@ -53,7 +53,7 @@ impl FromStr for Range { Err(inval) } } - (Some(n), Some(m)) if n.len() == 0 => { + (Some(n), Some(m)) if n.is_empty() => { if let Ok(high) = m.parse::() { if high > 0 { Ok(Range { low: 1, high }) diff --git a/src/install/install.rs b/src/install/install.rs index 300475abd..042d089c9 100644 --- a/src/install/install.rs +++ b/src/install/install.rs @@ -259,7 +259,7 @@ fn behaviour(matches: &getopts::Matches) -> Result { /// Returns an integer intended as a program return code. /// fn directory(paths: &[PathBuf], b: Behaviour) -> i32 { - if paths.len() < 1 { + if paths.is_empty() { println!("{} with -d requires at least one argument.", NAME); 1 } else { diff --git a/src/join/join.rs b/src/join/join.rs index 2f7b2dfbc..7ae82fe6e 100755 --- a/src/join/join.rs +++ b/src/join/join.rs @@ -186,7 +186,7 @@ impl Spec { let file_num = match chars.next() { Some('0') => { // Must be all alone without a field specifier. - if let None = chars.next() { + if chars.next().is_none() { return Spec::Key; } diff --git a/src/ln/ln.rs b/src/ln/ln.rs index c43be8aa3..f5f5ddf53 100644 --- a/src/ln/ln.rs +++ b/src/ln/ln.rs @@ -159,7 +159,7 @@ pub fn uumain(args: Vec) -> i32 { } fn exec(files: &[PathBuf], settings: &Settings) -> i32 { - if files.len() == 0 { + if files.is_empty() { show_error!( "missing file operand\nTry '{} --help' for more information.", NAME @@ -201,7 +201,7 @@ fn exec(files: &[PathBuf], settings: &Settings) -> i32 { ); return 1; } - assert!(files.len() != 0); + assert!(!files.is_empty()); match link(&files[0], &files[1], settings) { Ok(_) => 0, diff --git a/src/ls/ls.rs b/src/ls/ls.rs index f66698d92..3910937f2 100644 --- a/src/ls/ls.rs +++ b/src/ls/ls.rs @@ -531,7 +531,7 @@ fn get_file_name(name: &Path, strip: Option<&Path>) -> String { Some(prefix) => name.strip_prefix(prefix).unwrap_or(name), None => name, }; - if name.as_os_str().len() == 0 { + if name.as_os_str().is_empty() { name = Path::new("."); } name.to_string_lossy().into_owned() diff --git a/src/mv/mv.rs b/src/mv/mv.rs index 331c15ed1..5f96a5f1c 100644 --- a/src/mv/mv.rs +++ b/src/mv/mv.rs @@ -426,7 +426,7 @@ fn existing_backup_path(path: &PathBuf, suffix: &str) -> PathBuf { fn is_empty_dir(path: &PathBuf) -> bool { match fs::read_dir(path) { Ok(contents) => { - return contents.peekable().peek().is_none(); + contents.peekable().peek().is_none() }, Err(_e) => { false } } diff --git a/src/nl/nl.rs b/src/nl/nl.rs index 5c74dc712..51c3fc8c9 100644 --- a/src/nl/nl.rs +++ b/src/nl/nl.rs @@ -363,7 +363,7 @@ fn pass_regex(line: &str, re: ®ex::Regex) -> bool { } fn pass_nonempty(line: &str, _: ®ex::Regex) -> bool { - line.len() > 0 + !line.is_empty() } fn pass_none(_: &str, _: ®ex::Regex) -> bool { diff --git a/src/numfmt/numfmt.rs b/src/numfmt/numfmt.rs index 87bf53bcb..13d4c54c3 100644 --- a/src/numfmt/numfmt.rs +++ b/src/numfmt/numfmt.rs @@ -353,7 +353,7 @@ pub fn uumain(args: Vec) -> i32 { let options = parse_options(&matches).unwrap(); - if matches.free.len() == 0 { + if matches.free.is_empty() { handle_stdin(options).unwrap() } else { handle_args(&matches.free, options).unwrap() diff --git a/src/od/multifilereader.rs b/src/od/multifilereader.rs index b53216cab..b0fb34b8d 100644 --- a/src/od/multifilereader.rs +++ b/src/od/multifilereader.rs @@ -36,7 +36,7 @@ impl<'b> MultifileReader<'b> { fn next_file(&mut self) { // loop retries with subsequent files if err - normally 'loops' once loop { - if self.ni.len() == 0 { + if self.ni.is_empty() { self.curr_file = None; break; } diff --git a/src/od/parse_inputs.rs b/src/od/parse_inputs.rs index 5f8bbf147..9646c77b6 100644 --- a/src/od/parse_inputs.rs +++ b/src/od/parse_inputs.rs @@ -73,7 +73,7 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result bool { } } // path length - if path.join("/").len() == 0 { + if path.join("/").is_empty() { writeln!(&mut std::io::stderr(), "empty file name"); return false; } diff --git a/src/printf/tokenize/num_format/formatters/cninetyninehexfloatf.rs b/src/printf/tokenize/num_format/formatters/cninetyninehexfloatf.rs index 9d226818c..72dc13af2 100644 --- a/src/printf/tokenize/num_format/formatters/cninetyninehexfloatf.rs +++ b/src/printf/tokenize/num_format/formatters/cninetyninehexfloatf.rs @@ -60,7 +60,7 @@ fn get_primitive_hex( Some(pos) => (&str_in[..pos], &str_in[pos + 1..]), None => (&str_in[..], "0"), }; - if first_segment_raw.len() == 0 { + if first_segment_raw.is_empty() { first_segment_raw = "0"; } // convert to string, hexifying if input is in dec. diff --git a/src/printf/tokenize/num_format/formatters/float_common.rs b/src/printf/tokenize/num_format/formatters/float_common.rs index aefc024a3..15e8fd466 100644 --- a/src/printf/tokenize/num_format/formatters/float_common.rs +++ b/src/printf/tokenize/num_format/formatters/float_common.rs @@ -223,7 +223,7 @@ pub fn get_primitive_dec( Some(pos) => (&str_in[..pos], &str_in[pos + 1..]), None => (&str_in[..], "0"), }; - if first_segment_raw.len() == 0 { + if first_segment_raw.is_empty() { first_segment_raw = "0"; } // convert to string, de_hexifying if input is in hex. @@ -317,7 +317,7 @@ pub fn primitive_to_str_common(prim: &FormatPrimitive, field: &FormatField) -> S let decimal_places = field.second_field.unwrap_or(6); match prim.post_decimal { Some(ref post_decimal) => { - if post_decimal.len() > 0 && decimal_places > 0 { + if !post_decimal.is_empty() && decimal_places > 0 { final_str.push('.'); let len_avail = post_decimal.len() as u32; diff --git a/src/printf/tokenize/num_format/num_format.rs b/src/printf/tokenize/num_format/num_format.rs index cc83a7c17..6e4363d5a 100644 --- a/src/printf/tokenize/num_format/num_format.rs +++ b/src/printf/tokenize/num_format/num_format.rs @@ -52,7 +52,7 @@ fn get_provided(str_in_opt: Option<&String>) -> Option { for cont in byte_it { ignored.push(cont); } - if ignored.len() > 0 { + if !ignored.is_empty() { warn_char_constant_ign(ignored); } second_byte as u8 diff --git a/src/printf/tokenize/sub.rs b/src/printf/tokenize/sub.rs index 933da7af1..438fdbedc 100644 --- a/src/printf/tokenize/sub.rs +++ b/src/printf/tokenize/sub.rs @@ -190,7 +190,7 @@ impl SubParser { } match self.min_width_tmp.as_mut() { Some(x) => { - if (ch == '-' || ch == '*') && x.len() > 0 { + if (ch == '-' || ch == '*') && !x.is_empty() { err_conv(&self.text_so_far); } if ch == '*' { @@ -213,7 +213,7 @@ impl SubParser { } match self.second_field_tmp.as_mut() { Some(x) => { - if ch == '*' && x.len() > 0 { + if ch == '*' && !x.is_empty() { err_conv(&self.text_so_far); } if ch == '*' { @@ -252,7 +252,7 @@ impl SubParser { } } } - if !self.field_char.is_some() { + if self.field_char.is_none() { err_conv(&self.text_so_far); } let field_char_retrieved = self.field_char.unwrap(); diff --git a/src/printf/tokenize/unescaped_text.rs b/src/printf/tokenize/unescaped_text.rs index c036af5b6..9ae213818 100644 --- a/src/printf/tokenize/unescaped_text.rs +++ b/src/printf/tokenize/unescaped_text.rs @@ -201,7 +201,7 @@ impl UnescapedText { // on non hex or octal escapes is costly // then we can make it faster/more complex // with as-necessary draining. - if tmp_str.len() > 0 { + if !tmp_str.is_empty() { new_vec.extend(tmp_str.bytes()); tmp_str = String::new(); } @@ -228,7 +228,7 @@ impl UnescapedText { } } } - if tmp_str.len() > 0 { + if !tmp_str.is_empty() { new_vec.extend(tmp_str.bytes()); } } diff --git a/src/seq/seq.rs b/src/seq/seq.rs index 2558f5122..a3d1b55b3 100644 --- a/src/seq/seq.rs +++ b/src/seq/seq.rs @@ -189,11 +189,11 @@ pub fn uumain(args: Vec) -> i32 { Ok(m) => m, Err(f) => return f, }; - if free.len() < 1 || free.len() > 3 { + if free.is_empty() || free.len() > 3 { crash!( 1, "too {} operands.\nTry '{} --help' for more information.", - if free.len() < 1 { "few" } else { "many" }, + if free.is_empty() { "few" } else { "many" }, NAME ); } diff --git a/src/tail/tail.rs b/src/tail/tail.rs index 46056dc1a..acc45b612 100755 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -276,7 +276,7 @@ pub fn parse_size(mut size_slice: &str) -> Result { 1024u64 }; - let exponent = if size_slice.len() > 0 { + let exponent = if !size_slice.is_empty() { let mut has_suffix = true; let exp = match size_slice.chars().last().unwrap_or('_') { 'K' | 'k' => 1u64, diff --git a/src/test/test.rs b/src/test/test.rs index bf4a2b26a..a89ce7300 100644 --- a/src/test/test.rs +++ b/src/test/test.rs @@ -53,7 +53,7 @@ pub fn uumain(_: Vec) -> i32 { } fn one(args: &[&[u8]]) -> bool { - args[0].len() > 0 + !args[0].is_empty() } fn two(args: &[&[u8]], error: &mut bool) -> bool { @@ -212,13 +212,13 @@ enum Precedence { } fn parse_expr(mut args: &[&[u8]], error: &mut bool) -> bool { - if args.len() == 0 { + if args.is_empty() { false } else { let hashmap = setup_hashmap(); let lhs = dispatch(&mut args, error); - if args.len() > 0 { + if !args.is_empty() { parse_expr_helper(&hashmap, &mut args, lhs, Precedence::Unknown, error) } else { lhs @@ -237,11 +237,11 @@ fn parse_expr_helper<'a>( *error = true; &min_prec }); - while !*error && args.len() > 0 && prec as usize >= min_prec as usize { + while !*error && !args.is_empty() && prec as usize >= min_prec as usize { let op = args[0]; *args = &(*args)[1..]; let mut rhs = dispatch(args, error); - while args.len() > 0 { + while !args.is_empty() { let subprec = *hashmap.get(&args[0]).unwrap_or_else(|| { *error = true; &min_prec @@ -269,7 +269,7 @@ fn parse_expr_helper<'a>( Precedence::Paren => unimplemented!(), // TODO: implement parentheses _ => unreachable!(), }; - if args.len() > 0 { + if !args.is_empty() { prec = *hashmap.get(&args[0]).unwrap_or_else(|| { *error = true; &min_prec diff --git a/src/tr/expand.rs b/src/tr/expand.rs index d9d38688a..f35e1e563 100644 --- a/src/tr/expand.rs +++ b/src/tr/expand.rs @@ -43,7 +43,7 @@ impl<'a> Iterator for Unescape<'a> { #[inline] fn next(&mut self) -> Option { - if self.string.len() == 0 { + if self.string.is_empty() { return None; } diff --git a/src/truncate/truncate.rs b/src/truncate/truncate.rs index 40562d9b0..f6ee266e0 100644 --- a/src/truncate/truncate.rs +++ b/src/truncate/truncate.rs @@ -190,7 +190,7 @@ fn parse_size(size: &str) -> (u64, TruncateMode) { }; if slice.chars().last().unwrap().is_alphabetic() { slice = &slice[..slice.len() - 1]; - if slice.len() > 0 && slice.chars().last().unwrap().is_alphabetic() { + if !slice.is_empty() && slice.chars().last().unwrap().is_alphabetic() { slice = &slice[..slice.len() - 1]; } } diff --git a/src/uutils/uutils.rs b/src/uutils/uutils.rs index e8205b11b..36fd738ce 100644 --- a/src/uutils/uutils.rs +++ b/src/uutils/uutils.rs @@ -70,7 +70,7 @@ fn main() { } // try first arg as util name. - if args.len() >= 1 { + if !args.is_empty() { let util = &args[0][..]; match umap.get(util) {