Skip to content
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ lib*.a

### direnv ###
/.direnv/

*.code-workspace
Comment thread
Xylphy marked this conversation as resolved.
Outdated
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(fuzzing)',
'cfg(target_os, values("cygwin"))',
] }
#unused_qualifications = "warn" // TODO: fix warnings in uucore, then re-enable this lint
unused_qualifications = "warn"

[workspace.lints.clippy]
# The counts were generated with this command:
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn main() {
\n\
#[allow(clippy::too_many_lines)]
#[allow(clippy::unreadable_literal)]
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n"
fn util_map<T: Args>() -> UtilityMap<T> {\n"
.as_bytes(),
)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/bin/coreutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::cmp;
use std::ffi::OsString;
use std::io::{self, Write};
use std::process;
use uucore::Args;

const VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down
14 changes: 7 additions & 7 deletions src/bin/uudoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ fn usage<T: Args>(utils: &UtilityMap<T>) {
}

/// Generates the coreutils app for the utility map
fn gen_coreutils_app<T: Args>(util_map: &UtilityMap<T>) -> clap::Command {
let mut command = clap::Command::new("coreutils");
fn gen_coreutils_app<T: Args>(util_map: &UtilityMap<T>) -> Command {
let mut command = Command::new("coreutils");
for (name, (_, sub_app)) in util_map {
// Recreate a small subcommand with only the relevant info
// (name & short description)
let about = sub_app()
.get_about()
.expect("Could not get the 'about'")
.to_string();
let sub_app = clap::Command::new(name).about(about);
let sub_app = Command::new(name).about(about);
command = command.subcommand(sub_app);
}
command
Expand Down Expand Up @@ -172,7 +172,7 @@ fn main() -> io::Result<()> {
}
let utils = util_map::<Box<dyn Iterator<Item = OsString>>>();
match std::fs::create_dir("docs/src/utils/") {
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => Ok(()),
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => Ok(()),
x => x,
}?;

Expand Down Expand Up @@ -202,7 +202,7 @@ fn main() -> io::Result<()> {
let mut map = HashMap::new();
for platform in ["unix", "macos", "windows", "unix_android"] {
let platform_utils: Vec<String> = String::from_utf8(
std::process::Command::new("./util/show-utils.sh")
process::Command::new("./util/show-utils.sh")
.arg(format!("--features=feat_os_{platform}"))
.output()?
.stdout,
Expand All @@ -217,7 +217,7 @@ fn main() -> io::Result<()> {

// Linux is a special case because it can support selinux
let platform_utils: Vec<String> = String::from_utf8(
std::process::Command::new("./util/show-utils.sh")
process::Command::new("./util/show-utils.sh")
.arg("--features=feat_os_unix feat_selinux")
.output()?
.stdout,
Expand Down Expand Up @@ -547,7 +547,7 @@ fn write_zip_examples(
};

match format_examples(content, output_markdown) {
Err(e) => Err(std::io::Error::other(format!(
Err(e) => Err(io::Error::other(format!(
"Failed to format the tldr examples of {name}: {e}"
))),
Ok(s) => Ok(s),
Expand Down
2 changes: 1 addition & 1 deletion src/uu/base32/src/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ fn format_read_error(error: &io::Error) -> String {

/// Determines if the input buffer contains any padding ('=') ignoring trailing whitespace.
#[cfg(test)]
fn read_and_has_padding<R: std::io::Read>(input: &mut R) -> UResult<(bool, Vec<u8>)> {
fn read_and_has_padding<R: io::Read>(input: &mut R) -> UResult<(bool, Vec<u8>)> {
let mut buf = Vec::new();
input
.read_to_end(&mut buf)
Expand Down
4 changes: 2 additions & 2 deletions src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ fn handle_o_direct_write(f: &mut File, buf: &[u8], original_error: io::Error) ->
let flags_without_direct = oflags - OFlag::O_DIRECT;

// Remove O_DIRECT flag using nix
if fcntl(&mut *f, FcntlArg::F_SETFL(flags_without_direct)).is_err() {
if fcntl(&mut *f, F_SETFL(flags_without_direct)).is_err() {
Comment thread
Xylphy marked this conversation as resolved.
Outdated
return Err(original_error);
}

Expand All @@ -744,7 +744,7 @@ fn handle_o_direct_write(f: &mut File, buf: &[u8], original_error: io::Error) ->

// Restore O_DIRECT flag using nix (GNU doesn't restore it, but we'll be safer)
// Log any restoration errors without failing the operation
if let Err(os_err) = fcntl(&mut *f, FcntlArg::F_SETFL(oflags)) {
if let Err(os_err) = fcntl(&mut *f, F_SETFL(oflags)) {
// Just log the error, don't fail the whole operation
show_error!("Failed to restore O_DIRECT flag: {}", os_err);
}
Expand Down
6 changes: 2 additions & 4 deletions src/uu/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,9 @@ where

// Set environment variable to communicate to Rust child processes
// that SIGPIPE should be default (not ignored)
if matches!(action_kind, SignalActionKind::Default)
&& sig_value == nix::libc::SIGPIPE as usize
{
if matches!(action_kind, SignalActionKind::Default) && sig_value == libc::SIGPIPE as usize {
unsafe {
std::env::set_var("RUST_SIGPIPE", "default");
env::set_var("RUST_SIGPIPE", "default");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/uu/fold/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ fn process_utf8_chars<W: Write>(line: &str, ctx: &mut FoldContext<'_, W>) -> URe
// not coalesce zero-width scalars there.
if ctx.mode == WidthMode::Columns {
while let Some(&(_, next_ch)) = iter.peek() {
if unicode_width::UnicodeWidthChar::width(next_ch).unwrap_or(1) == 0 {
if UnicodeWidthChar::width(next_ch).unwrap_or(1) == 0 {
iter.next();
} else {
break;
Expand Down
4 changes: 2 additions & 2 deletions src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl<'a> StyleManager<'a> {
}

#[cfg(unix)]
fn indicator_for_special_file(&self, file_type: &std::fs::FileType) -> Option<Indicator> {
fn indicator_for_special_file(&self, file_type: &fs::FileType) -> Option<Indicator> {
if file_type.is_fifo() && self.has_indicator_style(Indicator::FIFO) {
return Some(Indicator::FIFO);
}
Expand All @@ -495,7 +495,7 @@ impl<'a> StyleManager<'a> {
}

#[cfg(not(unix))]
fn indicator_for_special_file(&self, _file_type: &std::fs::FileType) -> Option<Indicator> {
fn indicator_for_special_file(&self, _file_type: &fs::FileType) -> Option<Indicator> {
None
}

Expand Down
2 changes: 1 addition & 1 deletion src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3574,7 +3574,7 @@ fn get_security_context<'a>(
// For SMACK, use the path to get the label
// If must_dereference is true, we follow the symlink
let target_path = if must_dereference {
std::fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf())
fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf())
} else {
path.to_path_buf()
};
Expand Down
4 changes: 1 addition & 3 deletions src/uu/mkfifo/src/mkfifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let set_security_context = matches.get_flag(options::SECURITY_CONTEXT);
let context = matches.get_one::<String>(options::CONTEXT);
if set_security_context || context.is_some() {
uucore::smack::set_smack_label_and_cleanup(&f, context, |p| {
std::fs::remove_file(p)
})?;
uucore::smack::set_smack_label_and_cleanup(&f, context, |p| fs::remove_file(p))?;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ fn handle_two_paths(source: &Path, target: &Path, opts: &Options) -> UResult<()>
OverwriteMode::Force => {}
OverwriteMode::Default => {
let (writable, mode) = is_writable(target);
if !writable && std::io::stdin().is_terminal() {
if !writable && io::stdin().is_terminal() {
prompt_overwrite(target, mode)?;
}
}
Expand Down Expand Up @@ -741,7 +741,7 @@ fn rename(
OverwriteMode::Default => {
// GNU mv prompts when stdin is a TTY and target is not writable
let (writable, mode) = is_writable(to);
if !writable && std::io::stdin().is_terminal() {
if !writable && io::stdin().is_terminal() {
prompt_overwrite(to, mode)?;
}
}
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 @@ -580,7 +580,7 @@ fn extract_strings_from_input(
// Apply skip_bytes by reading and discarding
let mut skipped = 0u64;
while skipped < skip_bytes {
let to_skip = std::cmp::min(8192, skip_bytes - skipped);
let to_skip = cmp::min(8192, skip_bytes - skipped);
let mut skip_buf = vec![0u8; to_skip as usize];
match mf.read(&mut skip_buf) {
Ok(0) => break, // EOF reached
Expand Down
2 changes: 1 addition & 1 deletion src/uu/rm/src/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn verbose_removed_directory(path: &Path, options: &Options) {
}

/// Helper function to show error with context and return error status
fn show_removal_error(error: std::io::Error, path: &Path) -> bool {
fn show_removal_error(error: io::Error, path: &Path) -> bool {
if error.kind() == io::ErrorKind::PermissionDenied {
show_error!("cannot remove {}: Permission denied", path.quote());
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/shuf/src/random_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl SeededRng {
hasher.update(seed.as_bytes());
let seed = hasher.finalize();
let seed = seed.as_slice().try_into().unwrap();
Self(Box::new(rand_chacha::ChaCha12Rng::from_seed(seed)))
Self(Box::new(ChaCha12Rng::from_seed(seed)))
}

#[allow(clippy::many_single_char_names)] // use original lemire names for easy comparison
Expand Down
4 changes: 2 additions & 2 deletions src/uu/shuf/src/shuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|| translate!("shuf-error-failed-to-open-random-source", "file" => r.quote()),
)?;
let file = BufReader::new(file);
WrappedRng::File(compat_random_source::RandomSourceAdapter::new(file))
WrappedRng::File(RandomSourceAdapter::new(file))
}
};

Expand Down Expand Up @@ -389,7 +389,7 @@ impl Writable for u64 {

#[cold]
#[inline(never)]
fn handle_write_error(e: std::io::Error) -> Box<dyn uucore::error::UError> {
fn handle_write_error(e: Error) -> Box<dyn uucore::error::UError> {
Comment thread
Xylphy marked this conversation as resolved.
Outdated
use uucore::error::FromIo;
let ctx = translate!("shuf-error-write-failed");
e.map_err_context(move || ctx)
Expand Down
4 changes: 2 additions & 2 deletions src/uu/sort/src/buffer_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ mod tests {
fn desired_buffer_matches_total_when_small() {
let six_mebibytes = 6 * 1024 * 1024;
let expected = ((six_mebibytes as u128) * 12)
.clamp(six_mebibytes as u128, crate::MAX_AUTOMATIC_BUF_SIZE as u128);
.clamp(six_mebibytes as u128, MAX_AUTOMATIC_BUF_SIZE as u128);
Comment thread
Xylphy marked this conversation as resolved.
Outdated
assert_eq!(desired_file_buffer_bytes(six_mebibytes as u128), expected);
}

Expand All @@ -146,7 +146,7 @@ mod tests {
let large = 256 * 1024 * 1024; // 256 MiB
assert_eq!(
desired_file_buffer_bytes(large as u128),
crate::MAX_AUTOMATIC_BUF_SIZE as u128
MAX_AUTOMATIC_BUF_SIZE as u128
);
}
}
2 changes: 1 addition & 1 deletion src/uu/sort/src/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
};

const MAX_TOKEN_BUFFER_BYTES: usize = 4 * 1024 * 1024;
const MAX_TOKEN_BUFFER_ELEMS: usize = MAX_TOKEN_BUFFER_BYTES / std::mem::size_of::<Range<usize>>();
const MAX_TOKEN_BUFFER_ELEMS: usize = MAX_TOKEN_BUFFER_BYTES / size_of::<Range<usize>>();

self_cell!(
/// The chunk that is passed around between threads.
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// Initialize locale collation if needed (UTF-8 locales)
// This MUST happen before init_precomputed() to avoid the performance regression
#[cfg(feature = "i18n-collator")]
let needs_locale_collation = uucore::i18n::collator::init_locale_collation();
let needs_locale_collation = i18n::collator::init_locale_collation();

#[cfg(not(feature = "i18n-collator"))]
let needs_locale_collation = false;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/tail/src/tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn tail_file(
/// After opening, we clear O_NONBLOCK so subsequent reads block normally.
/// Without `--pid`, FIFOs block on open() until a writer connects (GNU behavior).
#[cfg(unix)]
fn open_file(path: &Path, use_nonblock_for_fifo: bool) -> std::io::Result<File> {
fn open_file(path: &Path, use_nonblock_for_fifo: bool) -> io::Result<File> {
use nix::fcntl::{FcntlArg, OFlag, fcntl};
use std::fs::OpenOptions;
use std::os::fd::AsFd;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/timeout/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn install_sigchld() {
/// We should terminate child process when receiving termination signals.
static SIGNALED: AtomicBool = AtomicBool::new(false);
/// Track which signal was received (0 = none/timeout expired naturally).
static RECEIVED_SIGNAL: std::sync::atomic::AtomicI32 = std::sync::atomic::AtomicI32::new(0);
static RECEIVED_SIGNAL: atomic::AtomicI32 = atomic::AtomicI32::new(0);

/// Install signal handlers for termination signals.
fn install_signal_handlers(term_signal: usize) {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/tsort/src/tsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ enum TsortError {

/// Wrapper for bubbling up IO errors
#[error("{0}")]
IO(#[from] std::io::Error),
IO(#[from] io::Error),
}

// Auxiliary struct, just for printing loop nodes via show! macro
Expand Down
14 changes: 7 additions & 7 deletions src/uucore/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
/// or if the current directory structure does not allow determining the project root.
fn project_root() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
let manifest_dir = env::var("CARGO_MANIFEST_DIR")?;
let uucore_path = std::path::Path::new(&manifest_dir);
let uucore_path = Path::new(&manifest_dir);

// Navigate from src/uucore to project root
let project_root = uucore_path
Expand Down Expand Up @@ -100,7 +100,7 @@ fn detect_target_utility() -> Option<String> {

// Check for a build configuration file in the target directory
if let Ok(target_dir) = env::var("CARGO_TARGET_DIR") {
let config_path = std::path::Path::new(&target_dir).join("uucore_target_util.txt");
let config_path = Path::new(&target_dir).join("uucore_target_util.txt");
if let Ok(content) = fs::read_to_string(&config_path) {
let util_name = content.trim();
if !util_name.is_empty() && util_name != "multicall" {
Expand Down Expand Up @@ -131,7 +131,7 @@ fn detect_target_utility() -> Option<String> {
/// Returns an error if the locales for `util_name` or `uucore` cannot be found
/// or if writing to the `embedded_file` fails.
fn embed_single_utility_locale(
embedded_file: &mut std::fs::File,
embedded_file: &mut File,
project_root: &Path,
util_name: &str,
locales_to_embed: &(String, Option<String>),
Expand Down Expand Up @@ -159,7 +159,7 @@ fn embed_single_utility_locale(
/// Returns an error if the `src/uu` directory cannot be read, if any utility
/// locales cannot be embedded, or if flushing the `embedded_file` fails.
fn embed_all_utility_locales(
embedded_file: &mut std::fs::File,
embedded_file: &mut File,
project_root: &Path,
locales_to_embed: &(String, Option<String>),
) -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -210,7 +210,7 @@ fn embed_all_utility_locales(
/// Returns an error if the directory containing the crate cannot be read or
/// if writing to the `embedded_file` fails.
fn embed_static_utility_locales(
embedded_file: &mut std::fs::File,
embedded_file: &mut File,
locales_to_embed: &(String, Option<String>),
) -> Result<(), Box<dyn std::error::Error>> {
use std::env;
Expand Down Expand Up @@ -303,7 +303,7 @@ where
/// Returns an error if the file at `locale_path` cannot be read or if
/// writing to `embedded_file` fails.
fn embed_locale_file(
embedded_file: &mut std::fs::File,
embedded_file: &mut File,
locale_path: &Path,
locale_key: &str,
locale: &str,
Expand Down Expand Up @@ -339,7 +339,7 @@ fn embed_locale_file(
/// Returns an error if `for_each_locale` fails, which typically happens if
/// reading a locale file or writing to the `embedded_file` fails.
fn embed_component_locales<F>(
embedded_file: &mut std::fs::File,
embedded_file: &mut File,
locales: &(String, Option<String>),
component_name: &str,
path_builder: F,
Expand Down
6 changes: 3 additions & 3 deletions src/uucore/src/lib/features/backup_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub mod arguments {
clap::Arg::new(OPT_BACKUP)
.long("backup")
.help("make a backup of each existing destination file")
.action(clap::ArgAction::Set)
.action(ArgAction::Set)
.require_equals(true)
.num_args(0..=1)
.value_name("CONTROL")
Expand All @@ -231,7 +231,7 @@ pub mod arguments {
.short('S')
.long("suffix")
.help("override the usual backup suffix")
.action(clap::ArgAction::Set)
.action(ArgAction::Set)
.value_name("SUFFIX")
.allow_hyphen_values(true)
}
Expand Down Expand Up @@ -505,7 +505,7 @@ mod tests {
// Environment variable for "VERSION_CONTROL"
static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL";

fn make_app() -> clap::Command {
fn make_app() -> Command {
Command::new("command")
.arg(arguments::backup())
.arg(arguments::backup_no_args())
Expand Down
Loading
Loading