refactor: inline format! args in a few places (#10730)

* refactor: inline format! args in a few places

* in one spot remove redundant mem alloc

* run clippy fix with mixed
This commit is contained in:
Yuri Astrakhan
2026-02-07 10:05:44 +01:00
committed by GitHub
parent a619d9618e
commit 05204864d6
31 changed files with 51 additions and 79 deletions
+1
View File
@@ -2,3 +2,4 @@ avoid-breaking-exported-api = false
check-private-items = true
cognitive-complexity-threshold = 24
missing-docs-in-crate-items = true
allow-mixed-uninlined-format-args = false
+1 -2
View File
@@ -32,8 +32,7 @@ pub fn not_found(util: &OsStr) -> ! {
/// Prints an "unrecognized option" error and exits
pub fn unrecognized_option(binary_name: &str, option: &OsStr) -> ! {
eprintln!(
"{}: unrecognized option '{}'",
binary_name,
"{binary_name}: unrecognized option '{}'",
option.to_string_lossy()
);
process::exit(1);
+3 -10
View File
@@ -318,19 +318,13 @@ impl Chmoder {
if new_mode != old_mode {
println!(
"mode of {} changed from {:04o} ({}) to {:04o} ({})",
"mode of {} changed from {old_mode:04o} ({current_permissions}) to {new_mode:04o} ({new_permissions})",
file_path.quote(),
old_mode,
current_permissions,
new_mode,
new_permissions
);
} else if self.verbose {
println!(
"mode of {} retained as {:04o} ({})",
"mode of {} retained as {old_mode:04o} ({current_permissions})",
file_path.quote(),
old_mode,
current_permissions
);
}
}
@@ -600,9 +594,8 @@ impl Chmoder {
if let Err(_e) = dir_fd.chmod_at(entry_name, new_mode, follow_symlinks) {
if self.verbose {
println!(
"failed to change mode of {} to {:o}",
"failed to change mode of {} to {new_mode:o}",
file_path.quote(),
new_mode
);
}
return Err(ChmodError::PermissionDenied(file_path.into()).into());
+1 -1
View File
@@ -1344,7 +1344,7 @@ fn show_error_if_needed(error: &CpError) {
// Format IoErrContext using strip_errno to remove "(os error N)" suffix
// for GNU-compatible output
CpError::IoErrContext(io_err, context) => {
show_error!("{}: {}", context, uucore::error::strip_errno(io_err));
show_error!("{context}: {}", uucore::error::strip_errno(io_err));
}
_ => {
show_error!("{error}");
+1 -1
View File
@@ -748,7 +748,7 @@ fn handle_o_direct_write(f: &mut File, buf: &[u8], original_error: io::Error) ->
// Log any restoration errors without failing the operation
if let Err(os_err) = fcntl(&mut *f, FcntlArg::F_SETFL(oflags)) {
// Just log the error, don't fail the whole operation
show_error!("Failed to restore O_DIRECT flag: {}", os_err);
show_error!("Failed to restore O_DIRECT flag: {os_err}");
}
write_result
+1 -1
View File
@@ -1091,7 +1091,7 @@ fn list_signal_handling(log: &SignalActionLog) {
SignalActionKind::Block => "BLOCK",
};
let signal_name = signal_name_by_value(sig_value).unwrap_or("?");
eprintln!("{:<10} ({}): {}", signal_name, sig_value as i32, action);
eprintln!("{signal_name:<10} ({}): {action}", sig_value as i32);
}
}
+1 -3
View File
@@ -223,9 +223,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} else {
show_error!(
"{}",
translate!("id-error-no-such-user",
"user" => users[i].quote()
)
translate!("id-error-no-such-user", "user" => users[i].quote())
);
set_exit_code(1);
if i + 1 >= users.len() {
+1 -1
View File
@@ -50,7 +50,7 @@ fn create_partial_overlap_files(
// File 2: keys (num_lines - overlap_count) to (2*num_lines - overlap_count - 1)
let start = num_lines - overlap_count;
for i in 0..num_lines {
writeln!(file2, "{:08} f2_data_{}", start + i, i).unwrap();
writeln!(file2, "{:08} f2_data_{i}", start + i).unwrap();
}
(
+2 -2
View File
@@ -95,7 +95,7 @@ fn mknod(file_name: &str, config: Config) -> i32 {
) {
// if it fails, delete the file
let _ = std::fs::remove_file(file_name);
eprintln!("{}: {}", uucore::util_name(), e);
eprintln!("{}: {e}", uucore::util_name());
return 1;
}
}
@@ -108,7 +108,7 @@ fn mknod(file_name: &str, config: Config) -> i32 {
std::fs::remove_file(p)
})
{
eprintln!("{}: {}", uucore::util_name(), e);
eprintln!("{}: {e}", uucore::util_name());
return 1;
}
}
+4 -5
View File
@@ -65,7 +65,7 @@ impl std::fmt::Display for HardlinkError {
)
}
Self::Metadata { path, error } => {
write!(f, "Metadata access error for {}: {}", path.quote(), error)
write!(f, "Metadata access error for {}: {error}", path.quote())
}
}
}
@@ -99,9 +99,8 @@ impl From<HardlinkError> for io::Error {
)),
HardlinkError::Metadata { path, error } => Self::other(format!(
"Metadata access error for {}: {}",
"Metadata access error for {}: {error}",
path.quote(),
error
)),
}
}
@@ -127,7 +126,7 @@ impl HardlinkTracker {
Err(e) => {
// Gracefully handle metadata errors by logging and continuing without hardlink tracking
if options.verbose {
eprintln!("warning: cannot get metadata for {}: {}", source.quote(), e);
eprintln!("warning: cannot get metadata for {}: {e}", source.quote());
}
return None;
}
@@ -180,7 +179,7 @@ impl HardlinkGroupScanner {
if let Err(e) = self.scan_single_path(file) {
if options.verbose {
// Only show warnings for verbose mode
eprintln!("warning: failed to scan {}: {}", file.quote(), e);
eprintln!("warning: failed to scan {}: {e}", file.quote());
}
// For non-verbose mode, silently continue for missing files
// This provides graceful degradation - we'll lose hardlink info for this file
+1 -1
View File
@@ -93,7 +93,7 @@ impl MultifileReader<'_> {
io::ErrorKind::PermissionDenied => "Permission denied",
_ => "I/O error",
};
show_error!("{}: {}", fname.maybe_quote().external(true), error_msg);
show_error!("{}: {error_msg}", fname.maybe_quote().external(true));
self.any_err = true;
}
}
+1 -1
View File
@@ -658,7 +658,7 @@ fn extract_strings_from_input(
// Note: GNU od does not output unterminated strings at EOF
// Strings must be null-terminated to be output
if mf.has_error() {
show_error!("{}", e);
show_error!("{e}");
return Err(1.into());
}
break;
+1 -2
View File
@@ -222,10 +222,9 @@ fn assert_alignment(
assert_eq!(
expected,
&spacing[..byte_size_block],
"unexpected spacing for byte_size={} print_width={} block_width={}",
"unexpected spacing for byte_size={} print_width={} block_width={print_width_block}",
type_info.byte_size,
type_info.print_width,
print_width_block
);
assert!(
spacing[byte_size_block..].iter().all(|&s| s == 0),
+4 -4
View File
@@ -91,7 +91,7 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result<CommandLineInputs,
let expected_msg = msg.split(" (os error").next().unwrap_or(&msg).to_string();
if e == expected_msg {
return Err(format!("{}: {}", input_strings[input_strings.len() - 1], e));
return Err(format!("{}: {e}", input_strings[input_strings.len() - 1]));
}
}
}
@@ -136,7 +136,7 @@ pub fn parse_inputs_traditional(input_strings: &[&str]) -> Result<CommandLineInp
m,
None,
))),
(_, Err(e)) => Err(format!("{}: {}", input_strings[1], e)),
(_, Err(e)) => Err(format!("{}: {e}", input_strings[1])),
}
}
3 => {
@@ -148,8 +148,8 @@ pub fn parse_inputs_traditional(input_strings: &[&str]) -> Result<CommandLineInp
n,
Some(m),
))),
(Err(e), _) => Err(format!("{}: {}", input_strings[1], e)),
(_, Err(e)) => Err(format!("{}: {}", input_strings[2], e)),
(Err(e), _) => Err(format!("{}: {e}", input_strings[1])),
(_, Err(e)) => Err(format!("{}: {e}", input_strings[2])),
}
}
_ => Err(translate!("od-error-too-many-inputs", "input" => input_strings[3])),
+2 -5
View File
@@ -1264,11 +1264,8 @@ fn header_content(options: &OutputOptions, page: usize) -> Vec<String> {
let padding_after_filename = space_for_filename - filename_len - padding_before_filename;
format!(
"{date_part}{:width1$}{filename}{:width2$}{page_part}",
"",
"",
width1 = padding_before_filename,
width2 = padding_after_filename
"{date_part}{:padding_before_filename$}{filename}{:padding_after_filename$}{page_part}",
"", ""
)
} else {
// If content is too long, just use single spaces
+1 -2
View File
@@ -70,8 +70,7 @@ pub fn ext_sort(
Err(err) => {
// Print the error and disable compression
eprintln!(
"sort: could not run compress program '{}': {}",
prog,
"sort: could not run compress program '{prog}': {}",
strip_errno(&err)
);
effective_settings.compress_prog = None;
+4 -5
View File
@@ -1467,7 +1467,7 @@ struct LegacyKeyWarning {
impl LegacyKeyWarning {
fn legacy_key_display(&self) -> String {
match self.to_field {
Some(to) => format!("+{} -{}", self.from_field, to),
Some(to) => format!("+{} -{to}", self.from_field),
None => format!("+{}", self.from_field),
}
}
@@ -1569,14 +1569,13 @@ fn legacy_key_to_k(from: &LegacyKeyPart, to: Option<&LegacyKeyPart>) -> String {
let start_char = from.char_pos.saturating_add(1);
let mut keydef = format!(
"{}{}{}",
start_field,
"{start_field}{}{}",
if from.char_pos == 0 {
String::new()
} else {
format!(".{start_char}")
},
from.opts
from.opts,
);
if let Some(to) = to {
@@ -2150,7 +2149,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
#[cfg(target_os = "linux")]
{
show_error!("{}", batch_too_large);
show_error!("{batch_too_large}");
translate!(
"sort-maximum-batch-size-rlimit",
+1 -2
View File
@@ -1303,13 +1303,12 @@ impl Stater {
};
format!(
" {}: %N\n {}: %-10s\t{}: %-10b {} {}: %-6o %F\n{}{}: (%04a/%10.10A) {}: (%5u/%8U) {}: (%5g/%8G)\n{}: %x\n{}: %y\n{}: %z\n {}: %w\n",
" {}: %N\n {}: %-10s\t{}: %-10b {} {}: %-6o %F\n{device_line}{}: (%04a/%10.10A) {}: (%5u/%8U) {}: (%5g/%8G)\n{}: %x\n{}: %y\n{}: %z\n {}: %w\n",
translate!("stat-word-file"),
translate!("stat-word-size"),
translate!("stat-word-blocks"),
translate!("stat-word-io"),
translate!("stat-word-block"),
device_line,
translate!("stat-word-access"),
translate!("stat-word-uid"),
translate!("stat-word-gid"),
+1 -1
View File
@@ -595,7 +595,7 @@ impl WrappedPrinter {
self.first_in_line = true;
}
print!("{}{}", self.prefix(), token);
print!("{}{token}", self.prefix());
self.current += token_len;
self.first_in_line = false;
}
+2 -2
View File
@@ -547,8 +547,8 @@ impl Sequence {
(Ok(c), Ok(())) => Ok(Self::Char(c)),
(Ok(c), Err(v)) => Err(BadSequence::MultipleCharInEquivalence(format!(
"{}{}",
String::from_utf8_lossy(&[c]).into_owned(),
String::from_utf8_lossy(v).into_owned()
String::from_utf8_lossy(&[c]),
String::from_utf8_lossy(v),
))),
},
)

Some files were not shown because too many files have changed in this diff Show More