Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,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
3 changes: 1 addition & 2 deletions src/common/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 3 additions & 10 deletions src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
2 changes: 1 addition & 1 deletion src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,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() {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/join/benches/join_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

(
Expand Down
4 changes: 2 additions & 2 deletions src/uu/mknod/src/mknod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/uu/mv/src/hardlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand Down Expand Up @@ -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
)),
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/uu/od/src/multifile_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/od/src/od.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/uu/od/src/output_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions src/uu/od/src/parse_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}
}
Expand Down Expand Up @@ -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 => {
Expand All @@ -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])),
Expand Down
7 changes: 2 additions & 5 deletions src/uu/pr/src/pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/uu/sort/src/ext_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/uu/stat/src/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/uu/stty/src/stty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/uu/tr/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference this was the redundant memory allocation

String::from_utf8_lossy(&[c]),
String::from_utf8_lossy(v),
))),
},
)
Expand Down
10 changes: 3 additions & 7 deletions src/uu/tsort/benches/tsort_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn generate_linear_chain(num_nodes: usize) -> Vec<u8> {
let mut data = Vec::new();

for i in 0..num_nodes.saturating_sub(1) {
data.extend_from_slice(format!("node{} node{}\n", i, i + 1).as_bytes());
data.extend_from_slice(format!("node{i} node{}\n", i + 1).as_bytes());
}

data
Expand Down Expand Up @@ -85,10 +85,8 @@ fn generate_wide_dag(num_nodes: usize) -> Vec<u8> {
for i in chain_start..chain_end.saturating_sub(1) {
data.extend_from_slice(
format!(
"chain{}_{} chain{}_{}\n",
chain,
"chain{chain}_{} chain{chain}_{}\n",
i - chain_start,
chain,
i + 1 - chain_start
)
.as_bytes(),
Expand All @@ -102,10 +100,8 @@ fn generate_wide_dag(num_nodes: usize) -> Vec<u8> {
let curr_mid = chain_start + chain_length / 4;
data.extend_from_slice(
format!(
"chain{}_{} chain{}_{}\n",
prev_chain,
"chain{prev_chain}_{} chain{chain}_{}\n",
prev_end - prev_chain * chain_length,
chain,
curr_mid - chain_start
)
.as_bytes(),
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/format/num_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ fn format_float_scientific(
return if force_decimal == ForceDecimal::Yes && precision == 0 {
format!("0.{exp_char}+00")
} else {
format!("{:.*}{exp_char}+00", precision, 0.0)
format!("{:.precision$}{exp_char}+00", 0.0)
};
}

Expand Down
5 changes: 2 additions & 3 deletions src/uucore/src/lib/features/perms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,13 @@ impl ChownExecutor {
// Use fchown (safe) to change the directory's ownership
if let Err(e) = dir_fd.fchown(self.dest_uid, self.dest_gid) {
let mut error_msg = format!(
"changing {} of {}: {}",
"changing {} of {}: {e}",
if self.verbosity.groups_only {
"group"
} else {
"ownership"
},
path.quote(),
e
);

if self.verbosity.level == VerbosityLevel::Verbose {
Expand Down Expand Up @@ -521,7 +520,7 @@ impl ChownExecutor {
entry_path.quote(),
strip_errno(&e)
);
show_error!("{}", msg);
show_error!("{msg}");
}
} else {
// Report the successful ownership change using the shared helper
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/selinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pub fn preserve_security_context(from_path: &Path, to_path: &Path) -> Result<(),
/// use uucore::selinux::get_getfattr_output;
///
/// let context = get_getfattr_output("/path/to/file");
/// println!("SELinux context: {}", context);
/// println!("SELinux context: {context}");
/// ```
pub fn get_getfattr_output(f: &str) -> String {
use std::process::Command;
Expand Down
3 changes: 1 addition & 2 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6500,8 +6500,7 @@ fn test_cp_archive_preserves_directory_permissions() {
assert_eq!(
mode & 0o777,
0o755,
"Directory {} has incorrect permissions: {:o}",
path,
"Directory {path} has incorrect permissions: {:o}",
mode & 0o777
);
};
Expand Down
3 changes: 1 addition & 2 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ fn test_date_set_hyphen_prefixed_values() {
// permission error, not argument parsing error
assert!(
result.stderr_str().starts_with("date: cannot set date: "),
"Expected permission error for '{}', but got: {}",
date_str,
"Expected permission error for '{date_str}', but got: {}",
result.stderr_str()
);
}
Expand Down
Loading
Loading