diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index d24d31be9..254d90d27 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -106,7 +106,7 @@ pub fn uu_app<'a>() -> Command<'a> { fn handle_obsolete(args: &[String]) -> (Vec, Option) { for (i, arg) in args.iter().enumerate() { let slice = &arg; - if slice.starts_with('-') && slice.chars().nth(1).map_or(false, |c| c.is_digit(10)) { + if slice.starts_with('-') && slice.chars().nth(1).map_or(false, |c| c.is_ascii_digit()) { let mut v = args.to_vec(); v.remove(i); return (v, Some(slice[1..].to_owned())); diff --git a/src/uu/head/src/parse.rs b/src/uu/head/src/parse.rs index ee543fe06..ea731ba29 100644 --- a/src/uu/head/src/parse.rs +++ b/src/uu/head/src/parse.rs @@ -20,7 +20,7 @@ pub fn parse_obsolete(src: &str) -> Option let mut has_num = false; let mut last_char = 0 as char; for (n, c) in &mut chars { - if c.is_digit(10) { + if c.is_ascii_digit() { has_num = true; num_end = n; } else { diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 17eec91ec..e189728e4 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -28,7 +28,7 @@ use std::{ cmp::Reverse, error::Error, ffi::{OsStr, OsString}, - fmt::Display, + fmt::{Display, Write as FmtWrite}, fs::{self, DirEntry, FileType, Metadata, ReadDir}, io::{stdout, BufWriter, ErrorKind, Stdout, Write}, path::{Path, PathBuf}, @@ -1825,7 +1825,7 @@ fn display_additional_leading_info( } else { "?".to_owned() }; - result.push_str(&format!("{} ", pad_left(&i, padding.inode))); + write!(result, "{} ", pad_left(&i, padding.inode)).unwrap(); } } @@ -1835,7 +1835,7 @@ fn display_additional_leading_info( } else { "?".to_owned() }; - result.push_str(&format!("{} ", pad_left(&s, padding.block_size),)); + write!(result, "{} ", pad_left(&s, padding.block_size)).unwrap(); } Ok(result) } diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs index f66e1ac0a..97f00b3c8 100644 --- a/src/uu/numfmt/src/format.rs +++ b/src/uu/numfmt/src/format.rs @@ -244,7 +244,7 @@ fn format_string( p => format!( "{:width$}", "", width = f.spacing[b % output_info.byte_size_block] - )); + ) + .unwrap(); match f.formatter_item_info.formatter { FormatWriter::IntWriter(func) => { @@ -626,12 +629,14 @@ fn print_bytes(prefix: &str, input_decoder: &MemoryDecoder, output_info: &Output let missing_spacing = output_info .print_width_line .saturating_sub(output_text.chars().count()); - output_text.push_str(&format!( + write!( + output_text, "{:>width$} {}", "", format_ascii_dump(input_decoder.get_buffer(0)), width = missing_spacing - )); + ) + .unwrap(); } if first { diff --git a/src/uu/od/src/parse_formats.rs b/src/uu/od/src/parse_formats.rs index 21971445d..f9f473dc8 100644 --- a/src/uu/od/src/parse_formats.rs +++ b/src/uu/od/src/parse_formats.rs @@ -244,7 +244,7 @@ fn is_format_size_decimal( return false; } match ch { - Some(d) if d.is_digit(10) => { + Some(d) if d.is_ascii_digit() => { decimal_size.push(d); true } diff --git a/src/uu/od/src/parse_inputs.rs b/src/uu/od/src/parse_inputs.rs index 45e664ce3..80b0d974f 100644 --- a/src/uu/od/src/parse_inputs.rs +++ b/src/uu/od/src/parse_inputs.rs @@ -10,7 +10,7 @@ pub trait CommandLineOpts { } /// Implementation for `getopts` -impl<'a> CommandLineOpts for ArgMatches { +impl CommandLineOpts for ArgMatches { fn inputs(&self) -> Vec<&str> { self.values_of(options::FILENAME) .map(|values| values.collect()) diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 2f253b580..40fe34218 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -13,7 +13,7 @@ use std::cmp; use std::collections::{BTreeSet, HashMap, HashSet}; use std::default::Default; use std::error::Error; -use std::fmt::{Display, Formatter}; +use std::fmt::{Display, Formatter, Write as FmtWrite}; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; use std::num::ParseIntError; @@ -572,7 +572,7 @@ fn format_tex_line( reference: &str, ) -> String { let mut output = String::new(); - output.push_str(&format!("\\{} ", config.macro_name)); + write!(output, "\\{} ", config.macro_name).unwrap(); let all_before = if config.input_ref { let before = &line[0..word_ref.position]; let before_start_trim_offset = @@ -587,18 +587,18 @@ fn format_tex_line( let after_chars_trim_idx = (word_ref.position_end, chars_line.len()); let all_after = &chars_line[after_chars_trim_idx.0..after_chars_trim_idx.1]; let (tail, before, after, head) = get_output_chunks(all_before, keyword, all_after, config); - output.push_str(&format!( - "{5}{0}{6}{5}{1}{6}{5}{2}{6}{5}{3}{6}{5}{4}{6}", + write!( + output, + "{{{0}}}{{{1}}}{{{2}}}{{{3}}}{{{4}}}", format_tex_field(&tail), format_tex_field(&before), format_tex_field(keyword), format_tex_field(&after), format_tex_field(&head), - "{", - "}" - )); + ) + .unwrap(); if config.auto_ref || config.input_ref { - output.push_str(&format!("{}{}{}", "{", format_tex_field(reference), "}")); + write!(output, "{{{}}}", format_tex_field(reference)).unwrap(); } output } @@ -615,7 +615,7 @@ fn format_roff_line( reference: &str, ) -> String { let mut output = String::new(); - output.push_str(&format!(".{}", config.macro_name)); + write!(output, ".{}", config.macro_name).unwrap(); let all_before = if config.input_ref { let before = &line[0..word_ref.position]; let before_start_trim_offset = @@ -630,16 +630,18 @@ fn format_roff_line( let after_chars_trim_idx = (word_ref.position_end, chars_line.len()); let all_after = &chars_line[after_chars_trim_idx.0..after_chars_trim_idx.1]; let (tail, before, after, head) = get_output_chunks(all_before, keyword, all_after, config); - output.push_str(&format!( + write!( + output, " \"{}\" \"{}\" \"{}{}\" \"{}\"", format_roff_field(&tail), format_roff_field(&before), format_roff_field(keyword), format_roff_field(&after), format_roff_field(&head) - )); + ) + .unwrap(); if config.auto_ref || config.input_ref { - output.push_str(&format!(" \"{}\"", format_roff_field(reference))); + write!(output, " \"{}\"", format_roff_field(reference)).unwrap(); } output } diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 141a7dd2c..3b423f4af 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -348,9 +348,9 @@ impl GlobalSettings { ]; let mut size_string = input.trim().to_string(); - if size_string.ends_with(|c: char| ALLOW_LIST.contains(&c) || c.is_digit(10)) { + if size_string.ends_with(|c: char| ALLOW_LIST.contains(&c) || c.is_ascii_digit()) { // b 1, K 1024 (default) - if size_string.ends_with(|c: char| c.is_digit(10)) { + if size_string.ends_with(|c: char| c.is_ascii_digit()) { size_string.push('K'); } else if size_string.ends_with('b') { size_string.pop(); diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 41c9ae4a9..3a585b106 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -197,8 +197,8 @@ impl ScanUtil for str { pub fn group_num(s: &str) -> Cow { let is_negative = s.starts_with('-'); - assert!(is_negative || s.chars().take(1).all(|c| c.is_digit(10))); - assert!(s.chars().skip(1).all(|c| c.is_digit(10))); + assert!(is_negative || s.chars().take(1).all(|c| c.is_ascii_digit())); + assert!(s.chars().skip(1).all(|c| c.is_ascii_digit())); if s.len() < 4 { return s.into(); } diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 816c86717..3250ea3f8 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -62,7 +62,7 @@ struct ProgramOptions { stderr: BufferType, } -impl<'a> TryFrom<&ArgMatches> for ProgramOptions { +impl TryFrom<&ArgMatches> for ProgramOptions { type Error = ProgramOptionsError; fn try_from(matches: &ArgMatches) -> Result { diff --git a/src/uu/tail/src/parse.rs b/src/uu/tail/src/parse.rs index ea9df9a02..d524adbc1 100644 --- a/src/uu/tail/src/parse.rs +++ b/src/uu/tail/src/parse.rs @@ -19,7 +19,7 @@ pub fn parse_obsolete(src: &str) -> Option let mut has_num = false; let mut last_char = 0 as char; for (n, c) in &mut chars { - if c.is_digit(10) { + if c.is_ascii_digit() { has_num = true; num_end = n; } else { diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index aecd492fe..27b0ebb56 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -50,11 +50,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let mut line = String::new(); match reader.read_line(&mut line) { Ok(_) => { - let tokens: Vec = line - .trim_end() - .split_whitespace() - .map(|s| s.to_owned()) - .collect(); + let tokens: Vec = line.split_whitespace().map(|s| s.to_owned()).collect(); if tokens.is_empty() { break; } diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index 47d96a381..15190af07 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -15,6 +15,7 @@ use uucore::utmpx::{self, time, Utmpx}; use clap::{crate_version, Arg, Command}; use std::borrow::Cow; use std::ffi::CStr; +use std::fmt::Write; use std::os::unix::fs::MetadataExt; use std::path::PathBuf; use uucore::{format_usage, InvalidEncodingHandling}; @@ -528,24 +529,24 @@ impl Who { let mut buf = String::with_capacity(64); let msg = vec![' ', state].into_iter().collect::(); - buf.push_str(&format!("{:<8}", user)); + write!(buf, "{:<8}", user).unwrap(); if self.include_mesg { buf.push_str(&msg); } - buf.push_str(&format!(" {:<12}", line)); + write!(buf, " {:<12}", line).unwrap(); // "%b %e %H:%M" (LC_ALL=C) let time_size = 3 + 2 + 2 + 1 + 2; - buf.push_str(&format!(" {:<1$}", time, time_size)); + write!(buf, " {:<1$}", time, time_size).unwrap(); if !self.short_output { if self.include_idle { - buf.push_str(&format!(" {:<6}", idle)); + write!(buf, " {:<6}", idle).unwrap(); } - buf.push_str(&format!(" {:>10}", pid)); + write!(buf, " {:>10}", pid).unwrap(); } - buf.push_str(&format!(" {:<8}", comment)); + write!(buf, " {:<8}", comment).unwrap(); if self.include_exit { - buf.push_str(&format!(" {:<12}", exit)); + write!(buf, " {:<12}", exit).unwrap(); } println!("{}", buf.trim_end()); } diff --git a/src/uucore/src/lib/parser/parse_size.rs b/src/uucore/src/lib/parser/parse_size.rs index 28a898825..de316c3d2 100644 --- a/src/uucore/src/lib/parser/parse_size.rs +++ b/src/uucore/src/lib/parser/parse_size.rs @@ -38,7 +38,7 @@ pub fn parse_size(size: &str) -> Result { } // Get the numeric part of the size argument. For example, if the // argument is "123K", then the numeric part is "123". - let numeric_string: String = size.chars().take_while(|c| c.is_digit(10)).collect(); + let numeric_string: String = size.chars().take_while(|c| c.is_ascii_digit()).collect(); let number: u64 = if !numeric_string.is_empty() { match numeric_string.parse() { Ok(n) => n, diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 72217a403..7b0390e70 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2840,7 +2840,7 @@ fn test_ls_context2() { let ts = TestScenario::new(util_name!()); for c_flag in ["-Z", "--context"] { ts.ucmd() - .args(&[c_flag, &"/"]) + .args(&[c_flag, "/"]) .succeeds() .stdout_only(unwrap_or_return!(expected_result(&ts, &[c_flag, "/"])).stdout_str()); }