From 5d986bfb4c193e05d69080d8cb788eaeeb6cb4d8 Mon Sep 17 00:00:00 2001 From: David Campbell Date: Thu, 19 Sep 2024 16:31:27 -0400 Subject: [PATCH 1/9] Fix clippy::manual_assert. --- src/uucore_procs/src/lib.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/uucore_procs/src/lib.rs b/src/uucore_procs/src/lib.rs index d46fd6e107d..11d89c97eb4 100644 --- a/src/uucore_procs/src/lib.rs +++ b/src/uucore_procs/src/lib.rs @@ -67,9 +67,10 @@ pub fn help_about(input: TokenStream) -> TokenStream { let input: Vec = input.into_iter().collect(); let filename = get_argument(&input, 0, "filename"); let text: String = uuhelp_parser::parse_about(&read_help(&filename)); - if text.is_empty() { - panic!("About text not found! Make sure the markdown format is correct"); - } + assert!( + !text.is_empty(), + "About text not found! Make sure the markdown format is correct" + ); TokenTree::Literal(Literal::string(&text)).into() } @@ -84,9 +85,10 @@ pub fn help_usage(input: TokenStream) -> TokenStream { let input: Vec = input.into_iter().collect(); let filename = get_argument(&input, 0, "filename"); let text: String = uuhelp_parser::parse_usage(&read_help(&filename)); - if text.is_empty() { - panic!("Usage text not found! Make sure the markdown format is correct"); - } + assert!( + !text.is_empty(), + "Usage text not found! Make sure the markdown format is correct" + ); TokenTree::Literal(Literal::string(&text)).into() } From 353eb53367a8b43152438189f374426037c428e0 Mon Sep 17 00:00:00 2001 From: David Campbell Date: Thu, 19 Sep 2024 17:56:27 -0400 Subject: [PATCH 2/9] Fix clippy::uninlined_format_args . --- src/uu/cksum/src/cksum.rs | 4 +-- src/uu/cp/src/copydir.rs | 2 +- src/uu/date/src/date.rs | 2 +- src/uu/df/src/df.rs | 4 +-- src/uu/dircolors/src/dircolors.rs | 17 +++++------ src/uu/du/src/du.rs | 7 ++--- src/uu/env/src/env.rs | 10 +++---- src/uu/env/src/parse_error.rs | 2 +- src/uu/env/src/variable_parser.rs | 4 +-- src/uu/expr/src/syntax_tree.rs | 2 +- src/uu/factor/src/factor.rs | 6 ++-- src/uu/fmt/src/fmt.rs | 4 +-- src/uu/kill/src/kill.rs | 2 +- src/uu/ls/src/dired.rs | 4 +-- src/uu/ls/src/ls.rs | 14 ++++----- src/uu/numfmt/src/numfmt.rs | 6 ++-- src/uu/paste/src/paste.rs | 5 +--- src/uu/split/src/platform/unix.rs | 2 +- src/uu/split/src/split.rs | 4 +-- src/uu/stat/src/stat.rs | 2 +- src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs | 2 +- src/uu/touch/src/error.rs | 14 ++++----- src/uu/touch/src/touch.rs | 6 ++-- src/uu/tr/src/tr.rs | 7 ++--- src/uu/tsort/src/tsort.rs | 2 +- src/uu/users/src/users.rs | 3 +- src/uucore/src/lib/features/checksum.rs | 9 ++---- .../src/lib/features/format/num_format.rs | 29 +++++------------- src/uucore/src/lib/features/perms.rs | 4 +-- src/uucore/src/lib/features/quoting_style.rs | 10 +++---- .../src/lib/parser/shortcut_value_parser.rs | 6 ++-- tests/by-util/test_cp.rs | 28 ++++++++--------- tests/by-util/test_dd.rs | 12 ++++---- tests/by-util/test_env.rs | 10 ++----- tests/by-util/test_ls.rs | 30 +++++++++---------- tests/by-util/test_mv.rs | 4 +-- tests/by-util/test_paste.rs | 2 +- tests/by-util/test_sort.rs | 7 ++--- tests/by-util/test_tail.rs | 8 ++--- 39 files changed, 127 insertions(+), 169 deletions(-) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 1a3c51b3e70..7ba9f78de6a 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -168,13 +168,13 @@ where } } }; - print!("{}", before_filename); + print!("{before_filename}"); if should_print_filename { // The filename might not be valid UTF-8, and filename.display() would mangle the names. // Therefore, emit the bytes directly to stdout, without any attempt at encoding them. let _dropped_result = stdout().write_all(os_str_as_bytes(filename.as_os_str())?); } - println!("{}", after_filename); + println!("{after_filename}"); } Ok(()) diff --git a/src/uu/cp/src/copydir.rs b/src/uu/cp/src/copydir.rs index 627f5a4de32..3bfc5524913 100644 --- a/src/uu/cp/src/copydir.rs +++ b/src/uu/cp/src/copydir.rs @@ -175,7 +175,7 @@ impl Entry { let source_is_dir = direntry.path().is_dir(); if path_ends_with_terminator(context.target) && source_is_dir { if let Err(e) = std::fs::create_dir_all(context.target) { - eprintln!("Failed to create directory: {}", e); + eprintln!("Failed to create directory: {e}"); } } else { descendant = descendant.strip_prefix(context.root)?.to_path_buf(); diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 02737dca28e..9c7d865643d 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -237,7 +237,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { None => { return Err(USimpleError::new( 1, - format!("invalid date {}", relative_time), + format!("invalid date {relative_time}"), )); } } diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index ee3615c9de7..517f8a31f1d 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -444,7 +444,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { None => { let filesystems = get_all_filesystems(&opt).map_err(|e| { let context = "cannot read table of mounted file systems"; - USimpleError::new(e.code(), format!("{}: {}", context, e)) + USimpleError::new(e.code(), format!("{context}: {e}")) })?; if filesystems.is_empty() { @@ -457,7 +457,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let paths: Vec<_> = paths.collect(); let filesystems = get_named_filesystems(&paths, &opt).map_err(|e| { let context = "cannot read table of mounted file systems"; - USimpleError::new(e.code(), format!("{}: {}", context, e)) + USimpleError::new(e.code(), format!("{context}: {e}")) })?; // This can happen if paths are given as command-line arguments diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 471ebdf0386..faef0683e71 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -78,14 +78,14 @@ pub fn generate_type_output(fmt: &OutputFmt) -> String { match fmt { OutputFmt::Display => FILE_TYPES .iter() - .map(|&(_, key, val)| format!("\x1b[{}m{}\t{}\x1b[0m", val, key, val)) + .map(|&(_, key, val)| format!("\x1b[{val}m{key}\t{val}\x1b[0m")) .collect::>() .join("\n"), _ => { // Existing logic for other formats FILE_TYPES .iter() - .map(|&(_, v1, v2)| format!("{}={}", v1, v2)) + .map(|&(_, v1, v2)| format!("{v1}={v2}")) .collect::>() .join(":") } @@ -100,8 +100,7 @@ fn generate_ls_colors(fmt: &OutputFmt, sep: &str) -> String { display_parts.push(type_output); for &(extension, code) in FILE_COLORS { let prefix = if extension.starts_with('*') { "" } else { "*" }; - let formatted_extension = - format!("\x1b[{}m{}{}\t{}\x1b[0m", code, prefix, extension, code); + let formatted_extension = format!("\x1b[{code}m{prefix}{extension}\t{code}\x1b[0m"); display_parts.push(formatted_extension); } display_parts.join("\n") @@ -111,8 +110,8 @@ fn generate_ls_colors(fmt: &OutputFmt, sep: &str) -> String { let mut parts = vec![]; for &(extension, code) in FILE_COLORS { let prefix = if extension.starts_with('*') { "" } else { "*" }; - let formatted_extension = format!("{}{}", prefix, extension); - parts.push(format!("{}={}", formatted_extension, code)); + let formatted_extension = format!("{prefix}{extension}"); + parts.push(format!("{formatted_extension}={code}")); } let (prefix, suffix) = get_colors_format_strings(fmt); let ls_colors = parts.join(sep); @@ -493,7 +492,7 @@ pub fn generate_dircolors_config() -> String { ); config.push_str("COLORTERM ?*\n"); for term in TERMS { - config.push_str(&format!("TERM {}\n", term)); + config.push_str(&format!("TERM {term}\n")); } config.push_str( @@ -514,14 +513,14 @@ pub fn generate_dircolors_config() -> String { ); for (name, _, code) in FILE_TYPES { - config.push_str(&format!("{} {}\n", name, code)); + config.push_str(&format!("{name} {code}\n")); } config.push_str("# List any file extensions like '.gz' or '.tar' that you would like ls\n"); config.push_str("# to color below. Put the extension, a space, and the color init string.\n"); for (ext, color) in FILE_COLORS { - config.push_str(&format!("{} {}\n", ext, color)); + config.push_str(&format!("{ext} {color}\n")); } config.push_str("# Subsequent TERM or COLORTERM entries, can be used to add / override\n"); config.push_str("# config specific to those matching environment variables."); diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 74fa4154db5..a35e9f77e76 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -594,7 +594,7 @@ fn read_files_from(file_name: &str) -> Result, std::io::Error> { if path.is_dir() { return Err(std::io::Error::new( std::io::ErrorKind::Other, - format!("{}: read error: Is a directory", file_name), + format!("{file_name}: read error: Is a directory"), )); } @@ -604,10 +604,7 @@ fn read_files_from(file_name: &str) -> Result, std::io::Error> { Err(e) if e.kind() == std::io::ErrorKind::NotFound => { return Err(std::io::Error::new( std::io::ErrorKind::Other, - format!( - "cannot open '{}' for reading: No such file or directory", - file_name - ), + format!("cannot open '{file_name}' for reading: No such file or directory"), )) } Err(e) => return Err(e), diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 229488cfb51..9e2e56d06c0 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -65,7 +65,7 @@ fn print_env(line_ending: LineEnding) { let stdout_raw = io::stdout(); let mut stdout = stdout_raw.lock(); for (n, v) in env::vars() { - write!(stdout, "{}={}{}", n, v, line_ending).unwrap(); + write!(stdout, "{n}={v}{line_ending}").unwrap(); } } @@ -281,15 +281,15 @@ pub fn parse_args_from_str(text: &NativeIntStr) -> UResult> USimpleError::new(125, "invalid backslash at end of string in -S") } parse_error::ParseError::InvalidSequenceBackslashXInMinusS { pos: _, c } => { - USimpleError::new(125, format!("invalid sequence '\\{}' in -S", c)) + USimpleError::new(125, format!("invalid sequence '\\{c}' in -S")) } parse_error::ParseError::MissingClosingQuote { pos: _, c: _ } => { USimpleError::new(125, "no terminating quote in -S string") } parse_error::ParseError::ParsingOfVariableNameFailed { pos, msg } => { - USimpleError::new(125, format!("variable name issue (at {}): {}", pos, msg,)) + USimpleError::new(125, format!("variable name issue (at {pos}): {msg}",)) } - _ => USimpleError::new(125, format!("Error: {:?}", e)), + _ => USimpleError::new(125, format!("Error: {e:?}")), }) } @@ -393,7 +393,7 @@ impl EnvAppData { | clap::error::ErrorKind::DisplayVersion => e.into(), _ => { // extent any real issue with parameter parsing by the ERROR_MSG_S_SHEBANG - let s = format!("{}", e); + let s = format!("{e}"); if !s.is_empty() { let s = s.trim_end(); uucore::show_error!("{}", s); diff --git a/src/uu/env/src/parse_error.rs b/src/uu/env/src/parse_error.rs index cbdba99ed90..84e5ba859f2 100644 --- a/src/uu/env/src/parse_error.rs +++ b/src/uu/env/src/parse_error.rs @@ -39,7 +39,7 @@ pub enum ParseError { impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(format!("{:?}", self).as_str()) + f.write_str(format!("{self:?}").as_str()) } } diff --git a/src/uu/env/src/variable_parser.rs b/src/uu/env/src/variable_parser.rs index ef80ff801a6..f225d494572 100644 --- a/src/uu/env/src/variable_parser.rs +++ b/src/uu/env/src/variable_parser.rs @@ -21,7 +21,7 @@ impl<'a, 'b> VariableParser<'a, 'b> { if c.is_ascii_digit() { return Err(ParseError::ParsingOfVariableNameFailed { pos: self.parser.get_peek_position(), - msg: format!("Unexpected character: '{}', expected variable name must not start with 0..9", c) }); + msg: format!("Unexpected character: '{c}', expected variable name must not start with 0..9") }); } } Ok(()) @@ -79,7 +79,7 @@ impl<'a, 'b> VariableParser<'a, 'b> { Some(c) => { return Err(ParseError::ParsingOfVariableNameFailed { pos: self.parser.get_peek_position(), - msg: format!("Unexpected character: '{}', expected a closing brace ('}}') or colon (':')", c) + msg: format!("Unexpected character: '{c}', expected a closing brace ('}}') or colon (':')") }) }, }; diff --git a/src/uu/expr/src/syntax_tree.rs b/src/uu/expr/src/syntax_tree.rs index 5aa9c93986b..0a947a158a4 100644 --- a/src/uu/expr/src/syntax_tree.rs +++ b/src/uu/expr/src/syntax_tree.rs @@ -139,7 +139,7 @@ impl StringOp { Self::Match => { let left = left.eval()?.eval_as_string(); let right = right.eval()?.eval_as_string(); - let re_string = format!("^{}", right); + let re_string = format!("^{right}"); let re = Regex::with_options( &re_string, RegexOptions::REGEX_OPTION_NONE, diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index 41fd860b3ce..e2356d91f7a 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -66,12 +66,12 @@ fn write_result( for (factor, n) in factorization { if print_exponents { if n > 1 { - write!(w, " {}^{}", factor, n)?; + write!(w, " {factor}^{n}")?; } else { - write!(w, " {}", factor)?; + write!(w, " {factor}")?; } } else { - w.write_all(format!(" {}", factor).repeat(n).as_bytes())?; + w.write_all(format!(" {factor}").repeat(n).as_bytes())?; } } writeln!(w)?; diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index 77858b041eb..45da48a91fc 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -129,7 +129,7 @@ impl FmtOptions { if width > MAX_WIDTH { return Err(USimpleError::new( 1, - format!("invalid width: '{}': Numerical result out of range", width), + format!("invalid width: '{width}': Numerical result out of range"), )); } @@ -241,7 +241,7 @@ fn extract_files(matches: &ArgMatches) -> UResult> { } else { let first_num = x.chars().nth(1).expect("a negative number should be at least two characters long"); Some(Err( - UUsageError::new(1, format!("invalid option -- {}; -WIDTH is recognized only when it is the first\noption; use -w N instead", first_num)) + UUsageError::new(1, format!("invalid option -- {first_num}; -WIDTH is recognized only when it is the first\noption; use -w N instead")) )) } } else { diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 1e60847c039..b5bcc0d7c0c 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -158,7 +158,7 @@ fn table() { .enumerate() .filter(|(_, s)| **s != "EXIT") { - println!("{0: >#2} {1}", idx, signal); + println!("{idx: >#2} {signal}"); } } diff --git a/src/uu/ls/src/dired.rs b/src/uu/ls/src/dired.rs index b039c8d90c5..0faec2c92f9 100644 --- a/src/uu/ls/src/dired.rs +++ b/src/uu/ls/src/dired.rs @@ -122,9 +122,9 @@ pub fn print_dired_output( /// Helper function to print positions with a given prefix. fn print_positions(prefix: &str, positions: &Vec) { - print!("{}", prefix); + print!("{prefix}"); for c in positions { - print!(" {}", c); + print!(" {c}"); } println!(); } diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 238a04bfaa3..7c8c3b44444 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2040,7 +2040,7 @@ fn show_dir_name(path_data: &PathData, out: &mut BufWriter, config: &Con if config.hyperlink && !config.dired { let name = escape_name(path_data.p_buf.as_os_str(), &config.quoting_style); let hyperlink = create_hyperlink(&name, path_data); - write!(out, "{}:", hyperlink).unwrap(); + write!(out, "{hyperlink}:").unwrap(); } else { write!(out, "{}:", path_data.p_buf.display()).unwrap(); } @@ -2091,7 +2091,7 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { // color is given if style_manager.get_normal_style().is_some() { let to_write = style_manager.reset(true); - write!(out, "{}", to_write)?; + write!(out, "{to_write}")?; } } @@ -2574,7 +2574,7 @@ fn display_items( Format::Commas => { let mut current_col = 0; if let Some(name) = names.next() { - write!(out, "{}", name)?; + write!(out, "{name}")?; current_col = ansi_width(&name) as u16 + 2; } for name in names { @@ -2582,10 +2582,10 @@ fn display_items( // If the width is 0 we print one single line if config.width != 0 && current_col + name_width + 1 > config.width { current_col = name_width + 2; - write!(out, ",\n{}", name)?; + write!(out, ",\n{name}")?; } else { current_col += name_width + 2; - write!(out, ", {}", name)?; + write!(out, ", {name}")?; } } // Current col is never zero again if names have been printed. @@ -2855,7 +2855,7 @@ fn display_item_long( ); let displayed_item = if quoted && !item_name.starts_with('\'') { - format!(" {}", item_name) + format!(" {item_name}") } else { item_name }; @@ -2969,7 +2969,7 @@ fn display_item_long( } write!(output_display, "{}{}", displayed_item, config.line_ending).unwrap(); } - write!(out, "{}", output_display)?; + write!(out, "{output_display}")?; Ok(()) } diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 42cdb1bad7a..9758d0aaae5 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -67,7 +67,7 @@ fn format_and_handle_validation(input_line: &str, options: &NumfmtOptions) -> UR } InvalidModes::Ignore => {} }; - println!("{}", input_line); + println!("{input_line}"); } Ok(()) @@ -428,8 +428,8 @@ mod tests { options.header = 0; let result = handle_buffer(BufReader::new(mock_buffer), &options) .expect_err("returned Ok after receiving IO error"); - let result_debug = format!("{:?}", result); - let result_display = format!("{}", result); + let result_debug = format!("{result:?}"); + let result_display = format!("{result}"); assert_eq!(result_debug, "IoError(\"broken pipe\")"); assert_eq!(result_display, "broken pipe"); assert_eq!(result.code(), 1); diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 118a66b81c2..3d4cf733ca8 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -111,10 +111,7 @@ fn paste( if delimiters.ends_with('\\') && !delimiters.ends_with("\\\\") { return Err(USimpleError::new( 1, - format!( - "delimiter list ends with an unescaped backslash: {}", - delimiters - ), + format!("delimiter list ends with an unescaped backslash: {delimiters}"), )); } diff --git a/src/uu/split/src/platform/unix.rs b/src/uu/split/src/platform/unix.rs index 1fd990e0a91..1e29739e2a7 100644 --- a/src/uu/split/src/platform/unix.rs +++ b/src/uu/split/src/platform/unix.rs @@ -104,7 +104,7 @@ impl Drop for FilterWriter { if return_code != 0 { show!(USimpleError::new( 1, - format!("Shell process returned {}", return_code) + format!("Shell process returned {return_code}") )); } } else { diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 691721fc42d..11fa04184df 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -658,7 +658,7 @@ where // Most likely continuous/infinite input stream return Err(io::Error::new( ErrorKind::Other, - format!("{}: cannot determine input size", input), + format!("{input}: cannot determine input size"), )); } else { // Could be that file size is larger than set read limit @@ -684,7 +684,7 @@ where // to address all possible file types and edge cases return Err(io::Error::new( ErrorKind::Other, - format!("{}: cannot determine file size", input), + format!("{input}: cannot determine file size"), )); } } diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 372a09274b1..ee417834461 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -586,7 +586,7 @@ impl Stater { let mut mount_list = read_fs_list() .map_err(|e| { let context = "cannot read table of mounted file systems"; - USimpleError::new(e.code(), format!("{}: {}", context, e)) + USimpleError::new(e.code(), format!("{context}: {e}")) })? .iter() .map(|mi| mi.mount_dir.clone()) diff --git a/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs b/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs index d744ca4c545..375ae5f2d2f 100644 --- a/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs +++ b/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs @@ -40,7 +40,7 @@ fn set_buffer(stream: *mut FILE, value: &str) { let buff_size: usize = match input.parse() { Ok(num) => num, Err(_) => { - eprintln!("failed to allocate a {} byte stdio buffer", value); + eprintln!("failed to allocate a {value} byte stdio buffer"); std::process::exit(1); } }; diff --git a/src/uu/touch/src/error.rs b/src/uu/touch/src/error.rs index 83bb9af7385..b39f3faf8d1 100644 --- a/src/uu/touch/src/error.rs +++ b/src/uu/touch/src/error.rs @@ -39,12 +39,10 @@ impl UError for TouchError {} impl Display for TouchError { fn fmt(&self, f: &mut Formatter) -> Result { match self { - Self::InvalidDateFormat(s) => write!(f, "Unable to parse date: {}", s), - Self::InvalidFiletime(time) => write!( - f, - "Source has invalid access or modification time: {}", - time, - ), + Self::InvalidDateFormat(s) => write!(f, "Unable to parse date: {s}"), + Self::InvalidFiletime(time) => { + write!(f, "Source has invalid access or modification time: {time}",) + } Self::ReferenceFileInaccessible(path, err) => { write!( f, @@ -54,9 +52,9 @@ impl Display for TouchError { ) } Self::WindowsStdoutPathError(code) => { - write!(f, "GetFinalPathNameByHandleW failed with code {}", code) + write!(f, "GetFinalPathNameByHandleW failed with code {code}") } - Self::TouchFileError { error, .. } => write!(f, "{}", error), + Self::TouchFileError { error, .. } => write!(f, "{error}"), } } } diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 391f7f0298d..f2c78ea61c3 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -585,8 +585,8 @@ fn parse_timestamp(s: &str) -> UResult { 15 => (YYYYMMDDHHMM_DOT_SS, s.to_owned()), 12 => (YYYYMMDDHHMM, s.to_owned()), // If we don't add "20", we have insufficient information to parse - 13 => (YYYYMMDDHHMM_DOT_SS, format!("20{}", s)), - 10 => (YYYYMMDDHHMM, format!("20{}", s)), + 13 => (YYYYMMDDHHMM_DOT_SS, format!("20{s}")), + 10 => (YYYYMMDDHHMM, format!("20{s}")), 11 => (YYYYMMDDHHMM_DOT_SS, format!("{}{}", current_year(), s)), 8 => (YYYYMMDDHHMM, format!("{}{}", current_year(), s)), _ => { @@ -766,7 +766,7 @@ mod tests { }, ) { Err(TouchError::InvalidFiletime(filetime)) => assert_eq!(filetime, invalid_filetime), - Err(e) => panic!("Expected TouchError::InvalidFiletime, got {}", e), + Err(e) => panic!("Expected TouchError::InvalidFiletime, got {e}"), Ok(_) => panic!("Expected to error with TouchError::InvalidFiletime but succeeded"), }; } diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 867d99755b1..01c4ea1d2f5 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -82,17 +82,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let op = sets[1].quote(); let msg = if sets_len == 2 { format!( - "{} {}\nOnly one string may be given when deleting without squeezing repeats.", - start, op, + "{start} {op}\nOnly one string may be given when deleting without squeezing repeats.", ) } else { - format!("{} {}", start, op,) + format!("{start} {op}",) }; return Err(UUsageError::new(1, msg)); } if sets_len > 2 { let op = sets[2].quote(); - let msg = format!("{} {}", start, op); + let msg = format!("{start} {op}"); return Err(UUsageError::new(1, msg)); } } diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index cd0b2030ae3..ca0319ecf48 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -36,7 +36,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if path.is_dir() { return Err(USimpleError::new( 1, - format!("{}: read error: Is a directory", input), + format!("{input}: read error: Is a directory"), )); } file_buf = File::open(path).map_err_context(|| input.to_string())?; diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index b886ab2f469..a9d856a598e 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -33,8 +33,7 @@ fn get_long_usage() -> String { let default_path: &str = OPENBSD_UTMP_FILE; format!( "Output who is currently logged in according to FILE. -If FILE is not specified, use {}. /var/log/wtmp as FILE is common.", - default_path +If FILE is not specified, use {default_path}. /var/log/wtmp as FILE is common." ) } diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index c5366e18156..40b270e0cb5 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -323,7 +323,7 @@ fn determine_regex(lines: &[String]) -> Option<(Regex, bool)> { fn bytes_to_hex(bytes: &[u8]) -> String { bytes .iter() - .map(|byte| format!("{:02x}", byte)) + .map(|byte| format!("{byte:02x}")) .collect::>() .join("") } @@ -365,10 +365,7 @@ fn get_file_to_check( match File::open(filename) { Ok(f) => { if f.metadata().ok()?.is_dir() { - show!(USimpleError::new( - 1, - format!("{}: Is a directory", filename) - )); + show!(USimpleError::new(1, format!("{filename}: Is a directory"))); None } else { Some(Box::new(f)) @@ -378,7 +375,7 @@ fn get_file_to_check( if !ignore_missing { // yes, we have both stderr and stdout here show!(err.map_err_context(|| filename.to_string())); - println!("{}: FAILED open or read", filename); + println!("{filename}: FAILED open or read"); } res.failed_open_file += 1; // we could not open the file but we want to continue diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index 676a1065d69..034f092daad 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -340,7 +340,7 @@ fn format_float_decimal(f: f64, precision: usize, force_decimal: ForceDecimal) - if precision == 0 && force_decimal == ForceDecimal::Yes { format!("{f:.0}.") } else { - format!("{f:.*}", precision) + format!("{f:.precision$}") } } @@ -380,10 +380,7 @@ fn format_float_scientific( Case::Uppercase => 'E', }; - format!( - "{normalized:.*}{additional_dot}{exp_char}{exponent:+03}", - precision - ) + format!("{normalized:.precision$}{additional_dot}{exp_char}{exponent:+03}") } fn format_float_shortest( @@ -427,7 +424,7 @@ fn format_float_shortest( "" }; - let mut normalized = format!("{normalized:.*}", precision); + let mut normalized = format!("{normalized:.precision$}"); if force_decimal == ForceDecimal::No { strip_fractional_zeroes_and_dot(&mut normalized); @@ -449,7 +446,7 @@ fn format_float_shortest( let mut formatted = if decimal_places == 0 && force_decimal == ForceDecimal::Yes { format!("{f:.0}.") } else { - format!("{f:.*}", decimal_places) + format!("{f:.decimal_places$}") }; if force_decimal == ForceDecimal::No { @@ -514,11 +511,7 @@ fn write_output( // Using min() because self.width could be 0, 0usize - 1usize should be avoided let remaining_width = width - min(width, sign_indicator.len()); match alignment { - NumberAlignment::Left => write!( - writer, - "{sign_indicator}{s: write!(writer, "{sign_indicator}{s: { let is_sign = sign_indicator.starts_with('-') || sign_indicator.starts_with('+'); // When sign_indicator is in ['-', '+'] if is_sign && remaining_width > 0 { @@ -526,19 +519,11 @@ fn write_output( s = sign_indicator + s.as_str(); write!(writer, "{s:>width$}", width = remaining_width + 1) // Since we now add sign_indicator and s together, plus 1 } else { - write!( - writer, - "{sign_indicator}{s:>width$}", - width = remaining_width - ) + write!(writer, "{sign_indicator}{s:>remaining_width$}") } } NumberAlignment::RightZero => { - write!( - writer, - "{sign_indicator}{s:0>width$}", - width = remaining_width - ) + write!(writer, "{sign_indicator}{s:0>remaining_width$}") } } } diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 880620c7ab1..ebb97042e13 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -220,8 +220,8 @@ fn is_root(path: &Path, would_traverse_symlink: bool) -> bool { Some(".") | Some("..") => true, Some(path_str) => { (path_str.ends_with(MAIN_SEPARATOR_STR)) - || (path_str.ends_with(&format!("{}.", MAIN_SEPARATOR_STR))) - || (path_str.ends_with(&format!("{}..", MAIN_SEPARATOR_STR))) + || (path_str.ends_with(&format!("{MAIN_SEPARATOR_STR}."))) + || (path_str.ends_with(&format!("{MAIN_SEPARATOR_STR}.."))) } }; // TODO: Once we reach MSRV 1.74.0, replace this abomination by something simpler, e.g. this: diff --git a/src/uucore/src/lib/features/quoting_style.rs b/src/uucore/src/lib/features/quoting_style.rs index 51ec55a64e1..cb98050a83b 100644 --- a/src/uucore/src/lib/features/quoting_style.rs +++ b/src/uucore/src/lib/features/quoting_style.rs @@ -801,31 +801,31 @@ mod tests { always_quote: false, show_control: false, }; - assert_eq!(format!("{}", style), "shell-escape"); + assert_eq!(format!("{style}"), "shell-escape"); let style = QuotingStyle::Shell { escape: false, always_quote: true, show_control: false, }; - assert_eq!(format!("{}", style), "shell-always-quote"); + assert_eq!(format!("{style}"), "shell-always-quote"); let style = QuotingStyle::Shell { escape: false, always_quote: false, show_control: true, }; - assert_eq!(format!("{}", style), "shell-show-control"); + assert_eq!(format!("{style}"), "shell-show-control"); let style = QuotingStyle::C { quotes: Quotes::Double, }; - assert_eq!(format!("{}", style), "C"); + assert_eq!(format!("{style}"), "C"); let style = QuotingStyle::Literal { show_control: false, }; - assert_eq!(format!("{}", style), "literal"); + assert_eq!(format!("{style}"), "literal"); } #[test] diff --git a/src/uucore/src/lib/parser/shortcut_value_parser.rs b/src/uucore/src/lib/parser/shortcut_value_parser.rs index 267cf5b756a..17c97802259 100644 --- a/src/uucore/src/lib/parser/shortcut_value_parser.rs +++ b/src/uucore/src/lib/parser/shortcut_value_parser.rs @@ -79,8 +79,7 @@ fn add_ambiguous_value_tip( err.insert( ContextKind::Suggested, ContextValue::StyledStrs(vec![format!( - "It looks like '{}' could match several values. Did you mean {}?", - value, formatted_possible_values + "It looks like '{value}' could match several values. Did you mean {formatted_possible_values}?" ) .into()]), ); @@ -175,8 +174,7 @@ mod tests { let result = parser.parse_ref(&cmd, None, OsStr::new(ambiguous_value)); assert_eq!(ErrorKind::InvalidValue, result.as_ref().unwrap_err().kind()); assert!(result.unwrap_err().to_string().contains(&format!( - "It looks like '{}' could match several values. Did you mean 'abcd' or 'abef'?", - ambiguous_value + "It looks like '{ambiguous_value}' could match several values. Did you mean 'abcd' or 'abef'?" ))); } diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 778beb7b45b..6f141db9700 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -341,7 +341,7 @@ fn test_cp_arg_update_none_fail() { .arg(TEST_HOW_ARE_YOU_SOURCE) .arg("--update=none-fail") .fails() - .stderr_contains(format!("not replacing '{}'", TEST_HOW_ARE_YOU_SOURCE)); + .stderr_contains(format!("not replacing '{TEST_HOW_ARE_YOU_SOURCE}'")); assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n"); } @@ -3897,7 +3897,7 @@ fn test_acl_preserve() { return; } Err(e) => { - println!("test skipped: setfacl failed with {}", e); + println!("test skipped: setfacl failed with {e}"); return; } } @@ -5581,7 +5581,7 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() { let child = scene .ucmd() .args(&[ - format!("--preserve={}", attr).as_str(), + format!("--preserve={attr}").as_str(), "-R", "--copy-contents", "--parents", @@ -5600,12 +5600,12 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() { start_time.elapsed() < timeout, "timed out: cp took too long to create destination directory" ); - if at.dir_exists(&format!("{}/{}", DEST_DIR, SRC_DIR)) { + if at.dir_exists(&format!("{DEST_DIR}/{SRC_DIR}")) { break; } std::thread::sleep(Duration::from_millis(100)); } - let mode = at.metadata(&format!("{}/{}", DEST_DIR, SRC_DIR)).mode(); + let mode = at.metadata(&format!("{DEST_DIR}/{SRC_DIR}")).mode(); #[allow(clippy::unnecessary_cast, clippy::cast_lossless)] let mask = if attr == "mode" { libc::S_IWGRP | libc::S_IWOTH @@ -5615,8 +5615,7 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() { assert_eq!( (mode & mask), 0, - "unwanted permissions are present - {}", - attr + "unwanted permissions are present - {attr}" ); at.write(FIFO, "done"); child.wait().unwrap().succeeded(); @@ -5673,18 +5672,15 @@ fn test_preserve_attrs_overriding_2() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; at.mkdir(FOLDER); - at.make_file(&format!("{}/{}", FOLDER, FILE1)); - at.set_mode(&format!("{}/{}", FOLDER, FILE1), 0o775); - at.hard_link( - &format!("{}/{}", FOLDER, FILE1), - &format!("{}/{}", FOLDER, FILE2), - ); + at.make_file(&format!("{FOLDER}/{FILE1}")); + at.set_mode(&format!("{FOLDER}/{FILE1}"), 0o775); + at.hard_link(&format!("{FOLDER}/{FILE1}"), &format!("{FOLDER}/{FILE2}")); args.append(&mut vec![FOLDER, DEST]); - let src_file1_metadata = at.metadata(&format!("{}/{}", FOLDER, FILE1)); + let src_file1_metadata = at.metadata(&format!("{FOLDER}/{FILE1}")); scene.ucmd().args(&args).succeeds(); at.dir_exists(DEST); - let dest_file1_metadata = at.metadata(&format!("{}/{}", DEST, FILE1)); - let dest_file2_metadata = at.metadata(&format!("{}/{}", DEST, FILE2)); + let dest_file1_metadata = at.metadata(&format!("{DEST}/{FILE1}")); + let dest_file2_metadata = at.metadata(&format!("{DEST}/{FILE2}")); assert_eq!( src_file1_metadata.modified().unwrap(), dest_file1_metadata.modified().unwrap() diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index bce1e31ecf4..e1e55054a6f 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -1649,7 +1649,7 @@ fn test_reading_partial_blocks_from_fifo() { // until the writer process starts). let mut reader_command = Command::new(TESTS_BINARY); let child = reader_command - .args(["dd", "ibs=3", "obs=3", &format!("if={}", fifoname)]) + .args(["dd", "ibs=3", "obs=3", &format!("if={fifoname}")]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() @@ -1661,7 +1661,7 @@ fn test_reading_partial_blocks_from_fifo() { writer_command .args([ "-c", - &format!("(printf \"ab\"; sleep 0.1; printf \"cd\") > {}", fifoname), + &format!("(printf \"ab\"; sleep 0.1; printf \"cd\") > {fifoname}"), ]) .spawn() .unwrap(); @@ -1692,7 +1692,7 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() { // `bs=N` takes precedence over `ibs=N` and `obs=N`. let mut reader_command = Command::new(TESTS_BINARY); let child = reader_command - .args(["dd", "bs=3", "ibs=1", "obs=1", &format!("if={}", fifoname)]) + .args(["dd", "bs=3", "ibs=1", "obs=1", &format!("if={fifoname}")]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() @@ -1704,7 +1704,7 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() { writer_command .args([ "-c", - &format!("(printf \"ab\"; sleep 0.1; printf \"cd\") > {}", fifoname), + &format!("(printf \"ab\"; sleep 0.1; printf \"cd\") > {fifoname}"), ]) .spawn() .unwrap(); @@ -1769,10 +1769,10 @@ fn test_stdin_stdout_not_rewound_even_when_connected_to_seekable_file() { .succeeds(); let err_file_content = std::fs::read_to_string(at.plus_as_string("err")).unwrap(); - println!("stderr:\n{}", err_file_content); + println!("stderr:\n{err_file_content}"); let out_file_content = std::fs::read_to_string(at.plus_as_string("out")).unwrap(); - println!("stdout:\n{}", out_file_content); + println!("stdout:\n{out_file_content}"); assert_eq!(out_file_content, "bde"); } diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 0a509c5d720..208feab6db2 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -935,7 +935,7 @@ mod tests_split_iterator { // minimal amount of quoting in typical cases. match escape_style(s) { EscapeStyle::None => s.into(), - EscapeStyle::SingleQuoted => format!("'{}'", s).into(), + EscapeStyle::SingleQuoted => format!("'{s}'").into(), EscapeStyle::Mixed => { let mut quoted = String::new(); quoted.push('\''); @@ -1015,17 +1015,13 @@ mod tests_split_iterator { match split(input) { Err(actual) => { panic!( - "[{i}] calling split({:?}):\nexpected: Ok({:?})\n actual: Err({:?})\n", - input, expected, actual + "[{i}] calling split({input:?}):\nexpected: Ok({expected:?})\n actual: Err({actual:?})\n" ); } Ok(actual) => { assert!( expected == actual.as_slice(), - "[{i}] After split({:?}).unwrap()\nexpected: {:?}\n actual: {:?}\n", - input, - expected, - actual + "[{i}] After split({input:?}).unwrap()\nexpected: {expected:?}\n actual: {actual:?}\n" ); } } diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index b54ff8c843a..90254d229e7 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -174,7 +174,7 @@ fn get_filesystem_type(scene: &TestScenario, path: &Path) -> String { let regex = Regex::new(regex_str).unwrap(); let m = regex.captures(&stdout_str).unwrap(); let fstype = m["fstype"].to_owned(); - println!("detected fstype: {}", fstype); + println!("detected fstype: {fstype}"); fstype } @@ -4120,7 +4120,7 @@ fn test_ls_dired_recursive_multiple() { let result = cmd.succeeds(); let output = result.stdout_str().to_string(); - println!("Output:\n{}", output); + println!("Output:\n{output}"); let dired_line = output .lines() @@ -4143,7 +4143,7 @@ fn test_ls_dired_recursive_multiple() { .unwrap() .trim() .to_string(); - println!("Extracted filename: {}", filename); + println!("Extracted filename: {filename}"); filename }) .collect(); @@ -4229,8 +4229,8 @@ fn test_ls_dired_complex() { .skip(1) .map(|s| s.parse().unwrap()) .collect(); - println!("{:?}", positions); - println!("Parsed byte positions: {:?}", positions); + println!("{positions:?}"); + println!("Parsed byte positions: {positions:?}"); assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions let filenames: Vec = positions @@ -4242,12 +4242,12 @@ fn test_ls_dired_complex() { .unwrap() .trim() .to_string(); - println!("Extracted filename: {}", filename); + println!("Extracted filename: {filename}"); filename }) .collect(); - println!("Extracted filenames: {:?}", filenames); + println!("Extracted filenames: {filenames:?}"); assert_eq!(filenames, vec!["a1", "a22", "a333", "a4444", "d"]); } @@ -4269,7 +4269,7 @@ fn test_ls_subdired_complex() { let result = cmd.succeeds(); let output = result.stdout_str().to_string(); - println!("Output:\n{}", output); + println!("Output:\n{output}"); let dired_line = output .lines() @@ -4280,7 +4280,7 @@ fn test_ls_subdired_complex() { .skip(1) .map(|s| s.parse().unwrap()) .collect(); - println!("Parsed byte positions: {:?}", positions); + println!("Parsed byte positions: {positions:?}"); assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions let dirnames: Vec = positions @@ -4290,12 +4290,12 @@ fn test_ls_subdired_complex() { let end_pos = chunk[1]; let dirname = String::from_utf8(output.as_bytes()[start_pos..end_pos].to_vec()).unwrap(); - println!("Extracted dirname: {}", dirname); + println!("Extracted dirname: {dirname}"); dirname }) .collect(); - println!("Extracted dirnames: {:?}", dirnames); + println!("Extracted dirnames: {dirnames:?}"); #[cfg(unix)] assert_eq!(dirnames, vec!["dir1", "dir1/c2", "dir1/d"]); #[cfg(windows)] @@ -4786,7 +4786,7 @@ fn test_acl_display() { return; } Err(e) => { - println!("test skipped: setfacl failed with {}", e); + println!("test skipped: setfacl failed with {e}"); return; } } @@ -4874,7 +4874,7 @@ fn test_ls_color_norm() { let expected = "\x1b[0m\x1b[07mnorm \x1b[0m\x1b[01mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line scene .ucmd() - .env("LS_COLORS", format!("{}:fi=1", colors)) + .env("LS_COLORS", format!("{colors}:fi=1")) .env("TIME_STYLE", "+norm") .arg("-gGU") .arg("--color") @@ -4889,7 +4889,7 @@ fn test_ls_color_norm() { "\x1b[0m\x1b[07mnorm \x1b[0mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line scene .ucmd() - .env("LS_COLORS", format!("{}:fi=", colors)) + .env("LS_COLORS", format!("{colors}:fi=")) .env("TIME_STYLE", "+norm") .arg("-gGU") .arg("--color") @@ -4903,7 +4903,7 @@ fn test_ls_color_norm() { "\x1b[0m\x1b[07mnorm \x1b[0mno_color\x1b[0m\n\x1b[07mnorm \x1b[0m\x1b[01;32mexe\x1b[0m\n"; // spell-checker:disable-line scene .ucmd() - .env("LS_COLORS", format!("{}:fi=0", colors)) + .env("LS_COLORS", format!("{colors}:fi=0")) .env("TIME_STYLE", "+norm") .arg("-gGU") .arg("--color") diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 7b100fe5c3f..daab2200956 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -1448,7 +1448,7 @@ fn test_mv_directory_into_subdirectory_of_itself_fails() { // check that it also errors out with / scene .ucmd() - .arg(format!("{}/", dir1)) + .arg(format!("{dir1}/")) .arg(dir2) .fails() .stderr_contains( @@ -1601,7 +1601,7 @@ fn test_acl() { return; } Err(e) => { - println!("test skipped: setfacl failed with {}", e); + println!("test skipped: setfacl failed with {e}"); return; } } diff --git a/tests/by-util/test_paste.rs b/tests/by-util/test_paste.rs index f3919309406..e770262c2a2 100644 --- a/tests/by-util/test_paste.rs +++ b/tests/by-util/test_paste.rs @@ -168,7 +168,7 @@ fn test_delimiter_list_ending_with_escaped_backslash() { let (at, mut ucmd) = at_and_ucmd!(); let mut ins = vec![]; for (i, one_in) in ["a\n", "b\n"].iter().enumerate() { - let file = format!("in{}", i); + let file = format!("in{i}"); at.write(&file, one_in); ins.push(file); } diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 67930fa401d..97bfc6a74d0 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1052,17 +1052,16 @@ fn test_batch_size_too_large() { let large_batch_size = "18446744073709551616"; TestScenario::new(util_name!()) .ucmd() - .arg(format!("--batch-size={}", large_batch_size)) + .arg(format!("--batch-size={large_batch_size}")) .fails() .code_is(2) .stderr_contains(format!( - "--batch-size argument '{}' too large", - large_batch_size + "--batch-size argument '{large_batch_size}' too large" )); #[cfg(target_os = "linux")] TestScenario::new(util_name!()) .ucmd() - .arg(format!("--batch-size={}", large_batch_size)) + .arg(format!("--batch-size={large_batch_size}")) .fails() .code_is(2) .stderr_contains("maximum --batch-size argument with current rlimit is"); diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index d1c32c3d720..4c7c52c7c18 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -3594,10 +3594,8 @@ fn test_when_argument_file_is_non_existent_unix_socket_address_then_error() { assert!(result.is_ok()); #[cfg(all(not(target_os = "freebsd"), not(target_os = "macos")))] - let expected_stderr = format!( - "tail: cannot open '{}' for reading: No such device or address\n", - socket - ); + let expected_stderr = + format!("tail: cannot open '{socket}' for reading: No such device or address\n"); #[cfg(target_os = "freebsd")] let expected_stderr = format!( "tail: cannot open '{}' for reading: Operation not supported\n", @@ -3622,7 +3620,7 @@ fn test_when_argument_file_is_non_existent_unix_socket_address_then_error() { let result = file.write_all(random_string.as_bytes()); assert!(result.is_ok()); - let expected_stdout = [format!("==> {} <==", path), random_string].join("\n"); + let expected_stdout = [format!("==> {path} <=="), random_string].join("\n"); ts.ucmd() .args(&["-c", "+0", path, socket]) .fails() From feae52797ba7340fd9a1bd7348aca81953802a14 Mon Sep 17 00:00:00 2001 From: David Campbell Date: Thu, 19 Sep 2024 18:05:14 -0400 Subject: [PATCH 3/9] Fix clippy::unnecessary_join. --- src/uucore/src/lib/features/checksum.rs | 3 +-- src/uuhelp_parser/src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 40b270e0cb5..06456c94f98 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -324,8 +324,7 @@ fn bytes_to_hex(bytes: &[u8]) -> String { bytes .iter() .map(|byte| format!("{byte:02x}")) - .collect::>() - .join("") + .collect::() } fn get_expected_checksum( diff --git a/src/uuhelp_parser/src/lib.rs b/src/uuhelp_parser/src/lib.rs index 8c5120f271f..da50c037b72 100644 --- a/src/uuhelp_parser/src/lib.rs +++ b/src/uuhelp_parser/src/lib.rs @@ -62,8 +62,7 @@ pub fn parse_usage(content: &str) -> String { "{}\n".to_string() } }) - .collect::>() - .join("") + .collect::() .trim() .to_string() } From cff8cc0e22f655f6cc2f00175e826b4f5c36209e Mon Sep 17 00:00:00 2001 From: David Campbell Date: Thu, 19 Sep 2024 18:08:51 -0400 Subject: [PATCH 4/9] Fix clippy::unreadable_literal. --- src/uu/df/src/table.rs | 18 ++-- src/uu/od/src/inputdecoder.rs | 4 +- src/uu/od/src/prn_float.rs | 85 ++++++++++--------- src/uucore/src/lib/features/format/human.rs | 2 +- .../src/lib/features/format/num_format.rs | 68 +++++++-------- .../src/lib/features/format/num_parser.rs | 2 +- src/uucore/src/lib/features/fsext.rs | 12 +-- src/uucore/src/lib/features/process.rs | 2 +- src/uucore/src/lib/mods/posix.rs | 6 +- src/uucore/src/lib/parser/parse_glob.rs | 2 +- 10 files changed, 102 insertions(+), 99 deletions(-) diff --git a/src/uu/df/src/table.rs b/src/uu/df/src/table.rs index daa30d1eef5..460bd03296e 100644 --- a/src/uu/df/src/table.rs +++ b/src/uu/df/src/table.rs @@ -841,12 +841,12 @@ mod tests { }, usage: crate::table::FsUsage { blocksize: 4096, - blocks: 244029695, - bfree: 125085030, - bavail: 125085030, + blocks: 244_029_695, + bfree: 125_085_030, + bavail: 125_085_030, bavail_top_bit_set: false, files: 999, - ffree: 1000000, + ffree: 1_000_000, }, }; @@ -871,12 +871,12 @@ mod tests { }, usage: crate::table::FsUsage { blocksize: 4096, - blocks: 244029695, - bfree: 125085030, - bavail: 125085030, + blocks: 244_029_695, + bfree: 125_085_030, + bavail: 125_085_030, bavail_top_bit_set: false, - files: 99999999999, - ffree: 999999, + files: 99_999_999_999, + ffree: 999_999, }, }; diff --git a/src/uu/od/src/inputdecoder.rs b/src/uu/od/src/inputdecoder.rs index e63eaed148f..62117d54608 100644 --- a/src/uu/od/src/inputdecoder.rs +++ b/src/uu/od/src/inputdecoder.rs @@ -179,8 +179,8 @@ mod tests { assert_eq!(-2.0, mem.read_float(0, 8)); assert_eq!(-2.0, mem.read_float(4, 4)); - assert_eq!(0xc000000000000000, mem.read_uint(0, 8)); - assert_eq!(0xc0000000, mem.read_uint(4, 4)); + assert_eq!(0xc000_0000_0000_0000, mem.read_uint(0, 8)); + assert_eq!(0xc000_0000, mem.read_uint(4, 4)); assert_eq!(0xc000, mem.read_uint(6, 2)); assert_eq!(0xc0, mem.read_uint(7, 1)); assert_eq!(&[0, 0xc0], mem.get_buffer(6)); diff --git a/src/uu/od/src/prn_float.rs b/src/uu/od/src/prn_float.rs index f44abf7c41c..f524a0203a9 100644 --- a/src/uu/od/src/prn_float.rs +++ b/src/uu/od/src/prn_float.rs @@ -94,72 +94,72 @@ fn format_float(f: f64, width: usize, precision: usize) -> String { #[allow(clippy::cognitive_complexity)] fn test_format_flo32() { assert_eq!(format_flo32(1.0), " 1.0000000"); - assert_eq!(format_flo32(9.9999990), " 9.9999990"); + assert_eq!(format_flo32(9.999_999_0), " 9.9999990"); assert_eq!(format_flo32(10.0), " 10.000000"); - assert_eq!(format_flo32(99.999977), " 99.999977"); - assert_eq!(format_flo32(99.999992), " 99.999992"); + assert_eq!(format_flo32(99.999_977), " 99.999977"); + assert_eq!(format_flo32(99.999_992), " 99.999992"); assert_eq!(format_flo32(100.0), " 100.00000"); assert_eq!(format_flo32(999.99994), " 999.99994"); assert_eq!(format_flo32(1000.0), " 1000.0000"); assert_eq!(format_flo32(9999.9990), " 9999.9990"); assert_eq!(format_flo32(10000.0), " 10000.000"); assert_eq!(format_flo32(99999.992), " 99999.992"); - assert_eq!(format_flo32(100000.0), " 100000.00"); - assert_eq!(format_flo32(999999.94), " 999999.94"); - assert_eq!(format_flo32(1000000.0), " 1000000.0"); - assert_eq!(format_flo32(9999999.0), " 9999999.0"); - assert_eq!(format_flo32(10000000.0), " 10000000"); - assert_eq!(format_flo32(99999992.0), " 99999992"); - assert_eq!(format_flo32(100000000.0), " 1.0000000e8"); - assert_eq!(format_flo32(9.9999994e8), " 9.9999994e8"); + assert_eq!(format_flo32(100_000.0), " 100000.00"); + assert_eq!(format_flo32(999_999.94), " 999999.94"); + assert_eq!(format_flo32(1_000_000.0), " 1000000.0"); + assert_eq!(format_flo32(9_999_999.0), " 9999999.0"); + assert_eq!(format_flo32(10_000_000.0), " 10000000"); + assert_eq!(format_flo32(99_999_992.0), " 99999992"); + assert_eq!(format_flo32(100_000_000.0), " 1.0000000e8"); + assert_eq!(format_flo32(9.999_999_4e8), " 9.9999994e8"); assert_eq!(format_flo32(1.0e9), " 1.0000000e9"); - assert_eq!(format_flo32(9.9999990e9), " 9.9999990e9"); + assert_eq!(format_flo32(9.999_999_0e9), " 9.9999990e9"); assert_eq!(format_flo32(1.0e10), " 1.0000000e10"); assert_eq!(format_flo32(0.1), " 0.10000000"); - assert_eq!(format_flo32(0.99999994), " 0.99999994"); - assert_eq!(format_flo32(0.010000001), " 1.0000001e-2"); - assert_eq!(format_flo32(0.099999994), " 9.9999994e-2"); + assert_eq!(format_flo32(0.999_999_94), " 0.99999994"); + assert_eq!(format_flo32(0.010_000_001), " 1.0000001e-2"); + assert_eq!(format_flo32(0.099_999_994), " 9.9999994e-2"); assert_eq!(format_flo32(0.001), " 1.0000000e-3"); - assert_eq!(format_flo32(0.0099999998), " 9.9999998e-3"); + assert_eq!(format_flo32(0.009_999_999_8), " 9.9999998e-3"); assert_eq!(format_flo32(-1.0), " -1.0000000"); - assert_eq!(format_flo32(-9.9999990), " -9.9999990"); + assert_eq!(format_flo32(-9.999_999_0), " -9.9999990"); assert_eq!(format_flo32(-10.0), " -10.000000"); - assert_eq!(format_flo32(-99.999977), " -99.999977"); - assert_eq!(format_flo32(-99.999992), " -99.999992"); + assert_eq!(format_flo32(-99.999_977), " -99.999977"); + assert_eq!(format_flo32(-99.999_992), " -99.999992"); assert_eq!(format_flo32(-100.0), " -100.00000"); assert_eq!(format_flo32(-999.99994), " -999.99994"); assert_eq!(format_flo32(-1000.0), " -1000.0000"); assert_eq!(format_flo32(-9999.9990), " -9999.9990"); assert_eq!(format_flo32(-10000.0), " -10000.000"); assert_eq!(format_flo32(-99999.992), " -99999.992"); - assert_eq!(format_flo32(-100000.0), " -100000.00"); - assert_eq!(format_flo32(-999999.94), " -999999.94"); - assert_eq!(format_flo32(-1000000.0), " -1000000.0"); - assert_eq!(format_flo32(-9999999.0), " -9999999.0"); - assert_eq!(format_flo32(-10000000.0), " -10000000"); - assert_eq!(format_flo32(-99999992.0), " -99999992"); - assert_eq!(format_flo32(-100000000.0), " -1.0000000e8"); - assert_eq!(format_flo32(-9.9999994e8), " -9.9999994e8"); + assert_eq!(format_flo32(-100_000.0), " -100000.00"); + assert_eq!(format_flo32(-999_999.94), " -999999.94"); + assert_eq!(format_flo32(-1_000_000.0), " -1000000.0"); + assert_eq!(format_flo32(-9_999_999.0), " -9999999.0"); + assert_eq!(format_flo32(-10_000_000.0), " -10000000"); + assert_eq!(format_flo32(-99_999_992.0), " -99999992"); + assert_eq!(format_flo32(-100_000_000.0), " -1.0000000e8"); + assert_eq!(format_flo32(-9.999_999_4e8), " -9.9999994e8"); assert_eq!(format_flo32(-1.0e9), " -1.0000000e9"); - assert_eq!(format_flo32(-9.9999990e9), " -9.9999990e9"); + assert_eq!(format_flo32(-9.999_999_0e9), " -9.9999990e9"); assert_eq!(format_flo32(-1.0e10), " -1.0000000e10"); assert_eq!(format_flo32(-0.1), " -0.10000000"); - assert_eq!(format_flo32(-0.99999994), " -0.99999994"); - assert_eq!(format_flo32(-0.010000001), " -1.0000001e-2"); - assert_eq!(format_flo32(-0.099999994), " -9.9999994e-2"); + assert_eq!(format_flo32(-0.999_999_94), " -0.99999994"); + assert_eq!(format_flo32(-0.010_000_001), " -1.0000001e-2"); + assert_eq!(format_flo32(-0.099_999_994), " -9.9999994e-2"); assert_eq!(format_flo32(-0.001), " -1.0000000e-3"); - assert_eq!(format_flo32(-0.0099999998), " -9.9999998e-3"); + assert_eq!(format_flo32(-0.009_999_999_8), " -9.9999998e-3"); - assert_eq!(format_flo32(3.4028233e38), " 3.4028233e38"); - assert_eq!(format_flo32(-3.4028233e38), " -3.4028233e38"); - assert_eq!(format_flo32(-1.1663108e-38), "-1.1663108e-38"); - assert_eq!(format_flo32(-4.7019771e-38), "-4.7019771e-38"); + assert_eq!(format_flo32(3.402_823_3e38), " 3.4028233e38"); + assert_eq!(format_flo32(-3.402_823_3e38), " -3.4028233e38"); + assert_eq!(format_flo32(-1.166_310_8e-38), "-1.1663108e-38"); + assert_eq!(format_flo32(-4.701_977_1e-38), "-4.7019771e-38"); assert_eq!(format_flo32(1e-45), " 1e-45"); - assert_eq!(format_flo32(-3.402823466e+38), " -3.4028235e38"); + assert_eq!(format_flo32(-3.402_823_466e+38), " -3.4028235e38"); assert_eq!(format_flo32(f32::NAN), " NaN"); assert_eq!(format_flo32(f32::INFINITY), " inf"); assert_eq!(format_flo32(f32::NEG_INFINITY), " -inf"); @@ -172,13 +172,16 @@ fn test_format_flo32() { fn test_format_flo64() { assert_eq!(format_flo64(1.0), " 1.0000000000000000"); assert_eq!(format_flo64(10.0), " 10.000000000000000"); - assert_eq!(format_flo64(1000000000000000.0), " 1000000000000000.0"); assert_eq!( - format_flo64(10000000000000000.0), + format_flo64(1_000_000_000_000_000.0), + " 1000000000000000.0" + ); + assert_eq!( + format_flo64(10_000_000_000_000_000.0), " 10000000000000000" ); assert_eq!( - format_flo64(100000000000000000.0), + format_flo64(100_000_000_000_000_000.0), " 1.0000000000000000e17" ); @@ -186,7 +189,7 @@ fn test_format_flo64() { assert_eq!(format_flo64(-0.01), " -1.0000000000000000e-2"); assert_eq!( - format_flo64(-2.2250738585072014e-308), + format_flo64(-2.225_073_858_507_201_4e-308), "-2.2250738585072014e-308" ); assert_eq!(format_flo64(4e-320), " 4e-320"); diff --git a/src/uucore/src/lib/features/format/human.rs b/src/uucore/src/lib/features/format/human.rs index 28d143a42e3..e33b77fcd2f 100644 --- a/src/uucore/src/lib/features/format/human.rs +++ b/src/uucore/src/lib/features/format/human.rs @@ -54,7 +54,7 @@ pub fn human_readable(size: u64, sfmt: SizeFormat) -> String { #[test] fn test_human_readable() { let test_cases = [ - (133456345, SizeFormat::Binary, "128M"), + (133_456_345, SizeFormat::Binary, "128M"), (12 * 1024 * 1024, SizeFormat::Binary, "12M"), (8500, SizeFormat::Binary, "8.4K"), ]; diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index 034f092daad..0cd5d6c1303 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -560,12 +560,12 @@ mod test { assert_eq!(f(0.0), "0.000000"); assert_eq!(f(1.0), "1.000000"); assert_eq!(f(100.0), "100.000000"); - assert_eq!(f(123456.789), "123456.789000"); - assert_eq!(f(12.3456789), "12.345679"); - assert_eq!(f(1000000.0), "1000000.000000"); - assert_eq!(f(99999999.0), "99999999.000000"); - assert_eq!(f(1.9999995), "1.999999"); - assert_eq!(f(1.9999996), "2.000000"); + assert_eq!(f(123_456.789), "123456.789000"); + assert_eq!(f(12.345_678_9), "12.345679"); + assert_eq!(f(1_000_000.0), "1000000.000000"); + assert_eq!(f(99_999_999.0), "99999999.000000"); + assert_eq!(f(1.999_999_5), "1.999999"); + assert_eq!(f(1.999_999_6), "2.000000"); } #[test] @@ -575,10 +575,10 @@ mod test { assert_eq!(f(0.0), "0.000000e+00"); assert_eq!(f(1.0), "1.000000e+00"); assert_eq!(f(100.0), "1.000000e+02"); - assert_eq!(f(123456.789), "1.234568e+05"); - assert_eq!(f(12.3456789), "1.234568e+01"); - assert_eq!(f(1000000.0), "1.000000e+06"); - assert_eq!(f(99999999.0), "1.000000e+08"); + assert_eq!(f(123_456.789), "1.234568e+05"); + assert_eq!(f(12.345_678_9), "1.234568e+01"); + assert_eq!(f(1_000_000.0), "1.000000e+06"); + assert_eq!(f(99_999_999.0), "1.000000e+08"); } #[test] @@ -589,19 +589,19 @@ mod test { assert_eq!(f(0.0), "0e+00"); assert_eq!(f(1.0), "1e+00"); assert_eq!(f(100.0), "1e+02"); - assert_eq!(f(123456.789), "1e+05"); - assert_eq!(f(12.3456789), "1e+01"); - assert_eq!(f(1000000.0), "1e+06"); - assert_eq!(f(99999999.0), "1e+08"); + assert_eq!(f(123_456.789), "1e+05"); + assert_eq!(f(12.345_678_9), "1e+01"); + assert_eq!(f(1_000_000.0), "1e+06"); + assert_eq!(f(99_999_999.0), "1e+08"); let f = |x| format_float_scientific(x, 0, Case::Lowercase, ForceDecimal::Yes); assert_eq!(f(0.0), "0.e+00"); assert_eq!(f(1.0), "1.e+00"); assert_eq!(f(100.0), "1.e+02"); - assert_eq!(f(123456.789), "1.e+05"); - assert_eq!(f(12.3456789), "1.e+01"); - assert_eq!(f(1000000.0), "1.e+06"); - assert_eq!(f(99999999.0), "1.e+08"); + assert_eq!(f(123_456.789), "1.e+05"); + assert_eq!(f(12.345_678_9), "1.e+01"); + assert_eq!(f(1_000_000.0), "1.e+06"); + assert_eq!(f(99_999_999.0), "1.e+08"); } #[test] @@ -611,10 +611,10 @@ mod test { assert_eq!(f(0.0), "0"); assert_eq!(f(1.0), "1"); assert_eq!(f(100.0), "100"); - assert_eq!(f(123456.789), "123457"); - assert_eq!(f(12.3456789), "12.3457"); - assert_eq!(f(1000000.0), "1e+06"); - assert_eq!(f(99999999.0), "1e+08"); + assert_eq!(f(123_456.789), "123457"); + assert_eq!(f(12.345_678_9), "12.3457"); + assert_eq!(f(1_000_000.0), "1e+06"); + assert_eq!(f(99_999_999.0), "1e+08"); } #[test] @@ -624,10 +624,10 @@ mod test { assert_eq!(f(0.0), "0.00000"); assert_eq!(f(1.0), "1.00000"); assert_eq!(f(100.0), "100.000"); - assert_eq!(f(123456.789), "123457."); - assert_eq!(f(12.3456789), "12.3457"); - assert_eq!(f(1000000.0), "1.00000e+06"); - assert_eq!(f(99999999.0), "1.00000e+08"); + assert_eq!(f(123_456.789), "123457."); + assert_eq!(f(12.345_678_9), "12.3457"); + assert_eq!(f(1_000_000.0), "1.00000e+06"); + assert_eq!(f(99_999_999.0), "1.00000e+08"); } #[test] @@ -637,19 +637,19 @@ mod test { assert_eq!(f(0.0), "0"); assert_eq!(f(1.0), "1"); assert_eq!(f(100.0), "1e+02"); - assert_eq!(f(123456.789), "1e+05"); - assert_eq!(f(12.3456789), "1e+01"); - assert_eq!(f(1000000.0), "1e+06"); - assert_eq!(f(99999999.0), "1e+08"); + assert_eq!(f(123_456.789), "1e+05"); + assert_eq!(f(12.345_678_9), "1e+01"); + assert_eq!(f(1_000_000.0), "1e+06"); + assert_eq!(f(99_999_999.0), "1e+08"); let f = |x| format_float_shortest(x, 0, Case::Lowercase, ForceDecimal::Yes); assert_eq!(f(0.0), "0."); assert_eq!(f(1.0), "1."); assert_eq!(f(100.0), "1.e+02"); - assert_eq!(f(123456.789), "1.e+05"); - assert_eq!(f(12.3456789), "1.e+01"); - assert_eq!(f(1000000.0), "1.e+06"); - assert_eq!(f(99999999.0), "1.e+08"); + assert_eq!(f(123_456.789), "1.e+05"); + assert_eq!(f(12.345_678_9), "1.e+01"); + assert_eq!(f(1_000_000.0), "1.e+06"); + assert_eq!(f(99_999_999.0), "1.e+08"); } #[test] diff --git a/src/uucore/src/lib/features/format/num_parser.rs b/src/uucore/src/lib/features/format/num_parser.rs index e0492b2581b..f7a72bccd36 100644 --- a/src/uucore/src/lib/features/format/num_parser.rs +++ b/src/uucore/src/lib/features/format/num_parser.rs @@ -356,7 +356,7 @@ mod tests { assert_eq!(Ok(0.5), ParsedNumber::parse_f64("0x.8")); assert_eq!(Ok(0.0625), ParsedNumber::parse_f64("0x.1")); - assert_eq!(Ok(15.0078125), ParsedNumber::parse_f64("0xf.02")); + assert_eq!(Ok(15.007_812_5), ParsedNumber::parse_f64("0xf.02")); } #[test] diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 5a6e4156d49..6bf7d18f404 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -907,7 +907,7 @@ pub fn pretty_fstype<'a>(fstype: i64) -> Cow<'a, str> { 0x0187 => "autofs".into(), 0x4246_5331 => "befs".into(), 0x6264_6576 => "bdevfs".into(), - 0xCA451A4E => "bcachefs".into(), + 0xCA45_1A4E => "bcachefs".into(), 0x1BAD_FACE => "bfs".into(), 0xCAFE_4A11 => "bpf_fs".into(), 0x4249_4E4D => "binfmt_misc".into(), @@ -1037,12 +1037,12 @@ mod tests { fn test_fs_type() { // spell-checker:disable assert_eq!("ext2/ext3", pretty_fstype(0xEF53)); - assert_eq!("tmpfs", pretty_fstype(0x01021994)); + assert_eq!("tmpfs", pretty_fstype(0x0102_1994)); assert_eq!("nfs", pretty_fstype(0x6969)); - assert_eq!("btrfs", pretty_fstype(0x9123683e)); - assert_eq!("xfs", pretty_fstype(0x58465342)); - assert_eq!("zfs", pretty_fstype(0x2FC12FC1)); - assert_eq!("ntfs", pretty_fstype(0x5346544e)); + assert_eq!("btrfs", pretty_fstype(0x9123_683e)); + assert_eq!("xfs", pretty_fstype(0x5846_5342)); + assert_eq!("zfs", pretty_fstype(0x2FC1_2FC1)); + assert_eq!("ntfs", pretty_fstype(0x5346_544e)); assert_eq!("fat", pretty_fstype(0x4006)); assert_eq!("UNKNOWN (0x1234)", pretty_fstype(0x1234)); // spell-checker:enable diff --git a/src/uucore/src/lib/features/process.rs b/src/uucore/src/lib/features/process.rs index 67f2ba2acd5..007e712fa5d 100644 --- a/src/uucore/src/lib/features/process.rs +++ b/src/uucore/src/lib/features/process.rs @@ -151,6 +151,6 @@ mod tests { assert!(getsid(getpid()).expect("getsid(getpid)") > 0); // This might caused tests failure but the probability is low. - assert!(getsid(999999).is_err()); + assert!(getsid(999_999).is_err()); } } diff --git a/src/uucore/src/lib/mods/posix.rs b/src/uucore/src/lib/mods/posix.rs index 05e928ca678..44c0d4f00a4 100644 --- a/src/uucore/src/lib/mods/posix.rs +++ b/src/uucore/src/lib/mods/posix.rs @@ -21,13 +21,13 @@ use std::env; /// '199209' for POSIX 1003.2-1992, which would define Obsolete mode -pub const OBSOLETE: usize = 199209; +pub const OBSOLETE: usize = 199_209; /// '200112' for POSIX 1003.1-2001, which is the minimum version for Traditional mode -pub const TRADITIONAL: usize = 200112; +pub const TRADITIONAL: usize = 200_112; /// '200809' for POSIX 1003.1-2008, which is the minimum version for Modern mode -pub const MODERN: usize = 200809; +pub const MODERN: usize = 200_809; /// Returns the value of the `_POSIX2_VERSION` environment variable if it is defined pub fn posix_version() -> Option { diff --git a/src/uucore/src/lib/parser/parse_glob.rs b/src/uucore/src/lib/parser/parse_glob.rs index 100d2edf561..08271788a02 100644 --- a/src/uucore/src/lib/parser/parse_glob.rs +++ b/src/uucore/src/lib/parser/parse_glob.rs @@ -97,7 +97,7 @@ mod tests { // test that we don't look for closing square brackets unnecessarily // Verifies issue #5584 - let chars = "^[".repeat(174571); + let chars = "^[".repeat(174_571); assert_eq!(fix_negation(chars.as_str()), chars); } From d0e30b2745bd6faafdb24919bca1c5858564ade8 Mon Sep 17 00:00:00 2001 From: David Campbell Date: Thu, 19 Sep 2024 18:55:31 -0400 Subject: [PATCH 5/9] Fix clippy::inconsistent_struct_constructor. --- src/uu/comm/src/comm.rs | 2 +- src/uu/cut/src/cut.rs | 5 +---- src/uu/df/src/filesystem.rs | 2 +- src/uu/fmt/src/fmt.rs | 4 ++-- src/uucore/src/lib/features/format/num_format.rs | 2 +- src/uucore/src/lib/features/fsext.rs | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index f8371729284..cae405865e6 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -42,7 +42,7 @@ struct LineReader { impl LineReader { fn new(input: Input, line_ending: LineEnding) -> Self { - Self { input, line_ending } + Self { line_ending, input } } fn read_line(&mut self, buf: &mut Vec) -> io::Result { diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 17dfea455d2..cd6eb22d30a 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -476,10 +476,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { Options { out_delimiter, line_ending, - field_opts: Some(FieldOptions { - only_delimited, - delimiter, - })}, + field_opts: Some(FieldOptions { delimiter, only_delimited })}, ) }), (2.., _, _, _) => Err( diff --git a/src/uu/df/src/filesystem.rs b/src/uu/df/src/filesystem.rs index 8cc639d68d9..5e86cf31781 100644 --- a/src/uu/df/src/filesystem.rs +++ b/src/uu/df/src/filesystem.rs @@ -111,9 +111,9 @@ impl Filesystem { #[cfg(windows)] let usage = FsUsage::new(Path::new(&_stat_path)).ok()?; Some(Self { + file, mount_info, usage, - file, }) } diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index 45da48a91fc..007e75dd64e 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -154,13 +154,13 @@ impl FmtOptions { crown, tagged, mail, - uniform, - quick, split_only, prefix, xprefix, anti_prefix, xanti_prefix, + uniform, + quick, width, goal, tabwidth, diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index 0cd5d6c1303..546171b96fe 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -204,9 +204,9 @@ impl Formatter for UnsignedInt { }; Ok(Self { + variant, width, precision, - variant, alignment, }) } diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 6bf7d18f404..c161db39fc7 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -179,9 +179,9 @@ impl MountInfo { dev_id, dev_name, fs_type, + mount_root, mount_dir, mount_option, - mount_root, remote, dummy, }) From 392344c93a5bbebc0bea7d5a79b778465ca18df6 Mon Sep 17 00:00:00 2001 From: David Campbell Date: Thu, 19 Sep 2024 19:45:57 -0400 Subject: [PATCH 6/9] Fix clippy::cloned_instead_of_copied. --- src/uu/hashsum/src/hashsum.rs | 2 +- src/uu/ptx/src/ptx.rs | 2 +- src/uu/tr/src/operation.rs | 4 ++-- src/uucore/src/lib/features/fs.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index f37f8445cc0..304938490a1 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -96,7 +96,7 @@ fn create_algorithm_from_flags(matches: &ArgMatches) -> UResult { set_or_err(detect_algo("b3sum", None)?)?; } if matches.get_flag("sha3") { - let bits = matches.get_one::("bits").cloned(); + let bits = matches.get_one::("bits").copied(); set_or_err(create_sha3(bits)?)?; } if matches.get_flag("sha3-224") { diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 0fb711798d0..3316b20bed0 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -129,7 +129,7 @@ impl WordFilter { HashSet::new() // really only chars found in file } else { // GNU off means at least these are considered - [' ', '\t', '\n'].iter().cloned().collect() + [' ', '\t', '\n'].iter().copied().collect() }; hs.extend(chars); Some(hs) diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index e6eb087486c..3eedb5ba99c 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -112,7 +112,7 @@ impl Sequence { Self::Class(class) => match class { Class::Alnum => Box::new((b'0'..=b'9').chain(b'A'..=b'Z').chain(b'a'..=b'z')), Class::Alpha => Box::new((b'A'..=b'Z').chain(b'a'..=b'z')), - Class::Blank => Box::new(unicode_table::BLANK.iter().cloned()), + Class::Blank => Box::new(unicode_table::BLANK.iter().copied()), Class::Control => Box::new((0..=31).chain(std::iter::once(127))), Class::Digit => Box::new(b'0'..=b'9'), Class::Graph => Box::new( @@ -137,7 +137,7 @@ impl Sequence { .chain(123..=126), ), Class::Punct => Box::new((33..=47).chain(58..=64).chain(91..=96).chain(123..=126)), - Class::Space => Box::new(unicode_table::SPACES.iter().cloned()), + Class::Space => Box::new(unicode_table::SPACES.iter().copied()), Class::Xdigit => Box::new((b'0'..=b'9').chain(b'A'..=b'F').chain(b'a'..=b'f')), Class::Lower => Box::new(b'a'..=b'z'), Class::Upper => Box::new(b'A'..=b'Z'), diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 73c61e0a3e4..e0c8ea79d3a 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -231,7 +231,7 @@ pub enum ResolveMode { /// replace this once that lands pub fn normalize_path(path: &Path) -> PathBuf { let mut components = path.components().peekable(); - let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { + let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().copied() { components.next(); PathBuf::from(c.as_os_str()) } else { From 3c26dd869e772bd8e476cef4a8f77851d63d106a Mon Sep 17 00:00:00 2001 From: David Campbell Date: Thu, 19 Sep 2024 19:52:01 -0400 Subject: [PATCH 7/9] Fix clippy::flat_map_option. --- src/uu/ls/src/ls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 7c8c3b44444..232250dcf3a 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -831,7 +831,7 @@ impl Config { options::FULL_TIME, ] .iter() - .flat_map(|opt| { + .filter_map(|opt| { if options.value_source(opt) == Some(clap::parser::ValueSource::CommandLine) { options.indices_of(opt) } else { From ae01996066b228921a68c2b357a5ba47270a305d Mon Sep 17 00:00:00 2001 From: David Campbell Date: Wed, 25 Sep 2024 12:48:48 -0400 Subject: [PATCH 8/9] Fix clippy::format_collect. --- src/uucore/src/lib/features/checksum.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 06456c94f98..1eb20397deb 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -23,6 +23,7 @@ use crate::{ }, util_name, }; +use std::fmt::Write; use std::io::stdin; use std::io::BufRead; use thiserror::Error; @@ -321,10 +322,10 @@ fn determine_regex(lines: &[String]) -> Option<(Regex, bool)> { // Converts bytes to a hexadecimal string fn bytes_to_hex(bytes: &[u8]) -> String { - bytes - .iter() - .map(|byte| format!("{byte:02x}")) - .collect::() + bytes.iter().fold(String::new(), |mut bytes, byte| { + write!(bytes, "{byte:02x}").unwrap(); + bytes + }) } fn get_expected_checksum( From d338206a6202e9b2442020e5795f6bdadb08dce5 Mon Sep 17 00:00:00 2001 From: David Campbell Date: Sat, 28 Sep 2024 16:09:41 -0400 Subject: [PATCH 9/9] Rename bytes to hex, allocate String with capacity. --- src/uucore/src/lib/features/checksum.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 1eb20397deb..c55d563930b 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -322,10 +322,12 @@ fn determine_regex(lines: &[String]) -> Option<(Regex, bool)> { // Converts bytes to a hexadecimal string fn bytes_to_hex(bytes: &[u8]) -> String { - bytes.iter().fold(String::new(), |mut bytes, byte| { - write!(bytes, "{byte:02x}").unwrap(); - bytes - }) + bytes + .iter() + .fold(String::with_capacity(bytes.len() * 2), |mut hex, byte| { + write!(hex, "{byte:02x}").unwrap(); + hex + }) } fn get_expected_checksum(