1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

chore: use inline formatting

Minor cleanup using clippy autofix.  This makes the code a bit more readable, and helps spot a few inefficiencies and possible bugs.

```
cargo clippy --fix --workspace -- -A clippy::all -W clippy::uninlined_format_args && cargo fmt
```
This commit is contained in:
Yuri Astrakhan 2025-04-07 22:56:21 -04:00
parent b7bf8c9467
commit 47b10539d0
17 changed files with 33 additions and 39 deletions

View file

@ -839,8 +839,7 @@ mod tests {
assert_eq!( assert_eq!(
has_padding(&mut cursor).unwrap(), has_padding(&mut cursor).unwrap(),
expected, expected,
"Failed for input: '{}'", "Failed for input: '{input}'"
input
); );
} }
} }

View file

@ -24,7 +24,7 @@ fn parse_gid_from_str(group: &str) -> Result<u32, String> {
// Handle :gid format // Handle :gid format
gid_str gid_str
.parse::<u32>() .parse::<u32>()
.map_err(|_| format!("invalid group id: '{}'", gid_str)) .map_err(|_| format!("invalid group id: '{gid_str}'"))
} else { } else {
// Try as group name first // Try as group name first
match entries::grp2gid(group) { match entries::grp2gid(group) {
@ -32,7 +32,7 @@ fn parse_gid_from_str(group: &str) -> Result<u32, String> {
// If group name lookup fails, try parsing as raw number // If group name lookup fails, try parsing as raw number
Err(_) => group Err(_) => group
.parse::<u32>() .parse::<u32>()
.map_err(|_| format!("invalid group: '{}'", group)), .map_err(|_| format!("invalid group: '{group}'")),
} }
} }
} }
@ -75,7 +75,7 @@ fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<GidUidOwnerFilter> {
Err(_) => { Err(_) => {
return Err(USimpleError::new( return Err(USimpleError::new(
1, 1,
format!("invalid user: '{}'", from_group), format!("invalid user: '{from_group}'"),
)); ));
} }
} }

10
src/uu/env/src/env.rs vendored
View file

@ -317,19 +317,19 @@ pub fn parse_args_from_str(text: &NativeIntStr) -> UResult<Vec<NativeIntString>>
} }
EnvError::EnvMissingClosingQuote(_, _) => USimpleError::new(125, e.to_string()), EnvError::EnvMissingClosingQuote(_, _) => USimpleError::new(125, e.to_string()),
EnvError::EnvParsingOfVariableMissingClosingBrace(pos) => { EnvError::EnvParsingOfVariableMissingClosingBrace(pos) => {
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e)) USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
} }
EnvError::EnvParsingOfMissingVariable(pos) => { EnvError::EnvParsingOfMissingVariable(pos) => {
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e)) USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
} }
EnvError::EnvParsingOfVariableMissingClosingBraceAfterValue(pos) => { EnvError::EnvParsingOfVariableMissingClosingBraceAfterValue(pos) => {
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e)) USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
} }
EnvError::EnvParsingOfVariableUnexpectedNumber(pos, _) => { EnvError::EnvParsingOfVariableUnexpectedNumber(pos, _) => {
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e)) USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
} }
EnvError::EnvParsingOfVariableExceptedBraceOrColon(pos, _) => { EnvError::EnvParsingOfVariableExceptedBraceOrColon(pos, _) => {
USimpleError::new(125, format!("variable name issue (at {pos}): {}", e)) USimpleError::new(125, format!("variable name issue (at {pos}): {e}"))
} }
_ => USimpleError::new(125, format!("Error: {e:?}")), _ => USimpleError::new(125, format!("Error: {e:?}")),
}) })

View file

@ -247,7 +247,7 @@ impl HeadOptions {
fn wrap_in_stdout_error(err: io::Error) -> io::Error { fn wrap_in_stdout_error(err: io::Error) -> io::Error {
io::Error::new( io::Error::new(
err.kind(), err.kind(),
format!("error writing 'standard output': {}", err), format!("error writing 'standard output': {err}"),
) )
} }

View file

@ -734,10 +734,7 @@ fn parse_separator(value_os: &OsString) -> UResult<SepSetting> {
match chars.next() { match chars.next() {
None => Ok(SepSetting::Char(value.into())), None => Ok(SepSetting::Char(value.into())),
Some('0') if c == '\\' => Ok(SepSetting::Byte(0)), Some('0') if c == '\\' => Ok(SepSetting::Byte(0)),
_ => Err(USimpleError::new( _ => Err(USimpleError::new(1, format!("multi-character tab {value}"))),
1,
format!("multi-character tab {}", value),
)),
} }
} }

View file

@ -60,7 +60,7 @@ enum LnError {
MissingDestination(PathBuf), MissingDestination(PathBuf),
#[error("extra operand {}\nTry '{} --help' for more information.", #[error("extra operand {}\nTry '{} --help' for more information.",
format!("{:?}", _0).trim_matches('"'), _1)] format!("{_0:?}").trim_matches('"'), _1)]
ExtraOperand(OsString, String), ExtraOperand(OsString, String),
} }

View file

@ -116,7 +116,7 @@ impl std::str::FromStr for QuotingStyle {
"shell" => Ok(QuotingStyle::Shell), "shell" => Ok(QuotingStyle::Shell),
"shell-escape-always" => Ok(QuotingStyle::ShellEscapeAlways), "shell-escape-always" => Ok(QuotingStyle::ShellEscapeAlways),
// The others aren't exposed to the user // The others aren't exposed to the user
_ => Err(format!("Invalid quoting style: {}", s)), _ => Err(format!("Invalid quoting style: {s}")),
} }
} }
} }
@ -335,9 +335,9 @@ fn quote_file_name(file_name: &str, quoting_style: &QuotingStyle) -> String {
match quoting_style { match quoting_style {
QuotingStyle::Locale | QuotingStyle::Shell => { QuotingStyle::Locale | QuotingStyle::Shell => {
let escaped = file_name.replace('\'', r"\'"); let escaped = file_name.replace('\'', r"\'");
format!("'{}'", escaped) format!("'{escaped}'")
} }
QuotingStyle::ShellEscapeAlways => format!("\"{}\"", file_name), QuotingStyle::ShellEscapeAlways => format!("\"{file_name}\""),
QuotingStyle::Quote => file_name.to_string(), QuotingStyle::Quote => file_name.to_string(),
} }
} }
@ -450,7 +450,7 @@ fn print_integer(
let extended = match precision { let extended = match precision {
Precision::NotSpecified => format!("{prefix}{arg}"), Precision::NotSpecified => format!("{prefix}{arg}"),
Precision::NoNumber => format!("{prefix}{arg}"), Precision::NoNumber => format!("{prefix}{arg}"),
Precision::Number(p) => format!("{prefix}{arg:0>precision$}", precision = p), Precision::Number(p) => format!("{prefix}{arg:0>p$}"),
}; };
pad_and_print(&extended, flags.left, width, padding_char); pad_and_print(&extended, flags.left, width, padding_char);
} }
@ -532,7 +532,7 @@ fn print_unsigned(
let s = match precision { let s = match precision {
Precision::NotSpecified => s, Precision::NotSpecified => s,
Precision::NoNumber => s, Precision::NoNumber => s,
Precision::Number(p) => format!("{s:0>precision$}", precision = p).into(), Precision::Number(p) => format!("{s:0>p$}").into(),
}; };
pad_and_print(&s, flags.left, width, padding_char); pad_and_print(&s, flags.left, width, padding_char);
} }
@ -557,7 +557,7 @@ fn print_unsigned_oct(
let s = match precision { let s = match precision {
Precision::NotSpecified => format!("{prefix}{num:o}"), Precision::NotSpecified => format!("{prefix}{num:o}"),
Precision::NoNumber => format!("{prefix}{num:o}"), Precision::NoNumber => format!("{prefix}{num:o}"),
Precision::Number(p) => format!("{prefix}{num:0>precision$o}", precision = p), Precision::Number(p) => format!("{prefix}{num:0>p$o}"),
}; };
pad_and_print(&s, flags.left, width, padding_char); pad_and_print(&s, flags.left, width, padding_char);
} }
@ -582,7 +582,7 @@ fn print_unsigned_hex(
let s = match precision { let s = match precision {
Precision::NotSpecified => format!("{prefix}{num:x}"), Precision::NotSpecified => format!("{prefix}{num:x}"),
Precision::NoNumber => format!("{prefix}{num:x}"), Precision::NoNumber => format!("{prefix}{num:x}"),
Precision::Number(p) => format!("{prefix}{num:0>precision$x}", precision = p), Precision::Number(p) => format!("{prefix}{num:0>p$x}"),
}; };
pad_and_print(&s, flags.left, width, padding_char); pad_and_print(&s, flags.left, width, padding_char);
} }
@ -994,7 +994,7 @@ impl Stater {
'R' => { 'R' => {
let major = meta.rdev() >> 8; let major = meta.rdev() >> 8;
let minor = meta.rdev() & 0xff; let minor = meta.rdev() & 0xff;
OutputType::Str(format!("{},{}", major, minor)) OutputType::Str(format!("{major},{minor}"))
} }
'r' => OutputType::Unsigned(meta.rdev()), 'r' => OutputType::Unsigned(meta.rdev()),
'H' => OutputType::Unsigned(meta.rdev() >> 8), // Major in decimal 'H' => OutputType::Unsigned(meta.rdev() >> 8), // Major in decimal

View file

@ -170,7 +170,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
127, 127,
format!("{EXEC_ERROR} No such file or directory"), format!("{EXEC_ERROR} No such file or directory"),
)), )),
_ => Err(USimpleError::new(1, format!("{EXEC_ERROR} {}", e))), _ => Err(USimpleError::new(1, format!("{EXEC_ERROR} {e}"))),
}; };
} }
}; };

View file

@ -236,7 +236,7 @@ fn default_uptime(matches: &ArgMatches) -> UResult<()> {
fn print_loadavg() { fn print_loadavg() {
match get_formatted_loadavg() { match get_formatted_loadavg() {
Err(_) => {} Err(_) => {}
Ok(s) => println!("{}", s), Ok(s) => println!("{s}"),
} }
} }

View file

@ -433,7 +433,7 @@ fn numbered_backup_path(path: &Path) -> PathBuf {
let file_name = path.file_name().unwrap_or_default(); let file_name = path.file_name().unwrap_or_default();
for i in 1_u64.. { for i in 1_u64.. {
let mut numbered_file_name = file_name.to_os_string(); let mut numbered_file_name = file_name.to_os_string();
numbered_file_name.push(format!(".~{}~", i)); numbered_file_name.push(format!(".~{i}~"));
let path = path.with_file_name(numbered_file_name); let path = path.with_file_name(numbered_file_name);
if !path.exists() { if !path.exists() {
return path; return path;

View file

@ -15,8 +15,8 @@ pub enum Error {
impl std::fmt::Display for Error { impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Error::WriteError(msg) => write!(f, "splice() write error: {}", msg), Error::WriteError(msg) => write!(f, "splice() write error: {msg}"),
Error::Io(err) => write!(f, "I/O error: {}", err), Error::Io(err) => write!(f, "I/O error: {err}"),
} }
} }
} }

View file

@ -863,7 +863,7 @@ mod tests {
("????????????????", "shell"), ("????????????????", "shell"),
(test_str, "shell-show"), (test_str, "shell-show"),
("'????????????????'", "shell-always"), ("'????????????????'", "shell-always"),
(&format!("'{}'", test_str), "shell-always-show"), (&format!("'{test_str}'"), "shell-always-show"),
( (
"''$'\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217'", "''$'\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217'",
"shell-escape", "shell-escape",
@ -893,7 +893,7 @@ mod tests {
("????????????????", "shell"), ("????????????????", "shell"),
(test_str, "shell-show"), (test_str, "shell-show"),
("'????????????????'", "shell-always"), ("'????????????????'", "shell-always"),
(&format!("'{}'", test_str), "shell-always-show"), (&format!("'{test_str}'"), "shell-always-show"),
( (
"''$'\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237'", "''$'\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237'",
"shell-escape", "shell-escape",

View file

@ -308,7 +308,7 @@ pub fn format_nusers(nusers: usize) -> String {
match nusers { match nusers {
0 => "0 user".to_string(), 0 => "0 user".to_string(),
1 => "1 user".to_string(), 1 => "1 user".to_string(),
_ => format!("{} users", nusers), _ => format!("{nusers} users"),
} }
} }

View file

@ -6093,9 +6093,7 @@ fn test_cp_preserve_xattr_readonly_source() {
let stdout = String::from_utf8_lossy(&getfattr_output.stdout); let stdout = String::from_utf8_lossy(&getfattr_output.stdout);
assert!( assert!(
stdout.contains(xattr_key), stdout.contains(xattr_key),
"Expected '{}' not found in getfattr output:\n{}", "Expected '{xattr_key}' not found in getfattr output:\n{stdout}"
xattr_key,
stdout
); );
at.set_readonly(source_file); at.set_readonly(source_file);

View file

@ -1457,7 +1457,7 @@ fn create_named_pipe_with_writer(path: &str, data: &str) -> std::process::Child
nix::unistd::mkfifo(path, nix::sys::stat::Mode::S_IRWXU).unwrap(); nix::unistd::mkfifo(path, nix::sys::stat::Mode::S_IRWXU).unwrap();
std::process::Command::new("sh") std::process::Command::new("sh")
.arg("-c") .arg("-c")
.arg(format!("printf '{}' > {path}", data)) .arg(format!("printf '{data}' > {path}"))
.spawn() .spawn()
.unwrap() .unwrap()
} }

View file

@ -435,7 +435,7 @@ fn test_all_but_last_bytes_large_file_piped() {
.len(); .len();
scene scene
.ucmd() .ucmd()
.args(&["-c", &format!("-{}", seq_19001_20000_file_length)]) .args(&["-c", &format!("-{seq_19001_20000_file_length}")])
.pipe_in_fixture(seq_20000_file_name) .pipe_in_fixture(seq_20000_file_name)
.succeeds() .succeeds()
.stdout_only_fixture(seq_19000_file_name); .stdout_only_fixture(seq_19000_file_name);
@ -695,7 +695,7 @@ fn test_validate_stdin_offset_bytes() {
.len(); .len();
scene scene
.ucmd() .ucmd()
.args(&["-c", &format!("-{}", seq_19001_20000_file_length)]) .args(&["-c", &format!("-{seq_19001_20000_file_length}")])
.set_stdin(file) .set_stdin(file)
.succeeds() .succeeds()
.stdout_only_fixture(seq_19000_file_name); .stdout_only_fixture(seq_19000_file_name);

View file

@ -20,7 +20,7 @@ fn init() {
std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY); std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY);
} }
// Print for debugging // Print for debugging
eprintln!("Setting UUTESTS_BINARY_PATH={}", TESTS_BINARY); eprintln!("Setting UUTESTS_BINARY_PATH={TESTS_BINARY}");
} }
#[test] #[test]