From 9f56bf5f07ad6d8e880589f5728d362d789fe075 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 9 Apr 2025 12:50:22 -0400 Subject: [PATCH 1/2] Enable and fix `unused_qualifications` lint Improve code readability --- Cargo.toml | 2 +- src/uu/base32/src/base_common.rs | 2 +- src/uu/basename/src/basename.rs | 2 +- src/uu/cat/src/cat.rs | 10 +-- src/uu/chcon/src/chcon.rs | 2 +- src/uu/chcon/src/fts.rs | 14 ++-- src/uu/cksum/src/cksum.rs | 2 +- src/uu/comm/src/comm.rs | 4 +- src/uu/cp/src/copydir.rs | 23 +++--- src/uu/cp/src/cp.rs | 12 +-- src/uu/csplit/src/csplit.rs | 4 +- src/uu/cut/src/cut.rs | 2 +- src/uu/dd/src/dd.rs | 28 +++---- src/uu/du/src/du.rs | 2 +- src/uu/env/src/env.rs | 12 +-- src/uu/factor/src/factor.rs | 4 +- src/uu/head/src/head.rs | 47 +++++------- src/uu/install/src/install.rs | 8 +- src/uu/kill/src/kill.rs | 2 +- src/uu/ls/src/ls.rs | 16 ++-- src/uu/more/src/more.rs | 18 ++--- src/uu/nohup/src/nohup.rs | 2 +- src/uu/numfmt/src/numfmt.rs | 109 +++++++++++++--------------- src/uu/od/src/multifilereader.rs | 2 +- src/uu/rm/src/rm.rs | 14 ++-- src/uu/rmdir/src/rmdir.rs | 2 +- src/uu/shuf/src/shuf.rs | 6 +- src/uu/sleep/src/sleep.rs | 2 +- src/uu/sort/src/merge.rs | 2 +- src/uu/sort/src/sort.rs | 4 +- src/uu/split/src/number.rs | 4 +- src/uu/split/src/platform/unix.rs | 4 +- src/uu/split/src/split.rs | 45 +++++------- src/uu/stat/src/stat.rs | 5 +- src/uu/tail/src/args.rs | 4 +- src/uu/tail/src/follow/watch.rs | 2 +- src/uu/tail/src/platform/unix.rs | 6 +- src/uu/tail/src/platform/windows.rs | 4 +- src/uu/tail/src/tail.rs | 6 +- src/uu/timeout/src/timeout.rs | 2 +- src/uu/touch/src/touch.rs | 4 +- src/uu/truncate/src/truncate.rs | 2 +- src/uu/unexpand/src/unexpand.rs | 2 +- src/uu/wc/src/wc.rs | 2 +- 44 files changed, 214 insertions(+), 237 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c111428f0..2961fec73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -589,7 +589,7 @@ pedantic = { level = "deny", priority = -1 } # Eventually the clippy settings from the `[lints]` section should be moved here. # In order to use these, all crates have `[lints] workspace = true` section. [workspace.lints.rust] -# unused_qualifications = "warn" +unused_qualifications = "warn" [workspace.lints.clippy] all = { level = "deny", priority = -1 } diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index d1151bdd2..05bfc89b2 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -139,7 +139,7 @@ pub fn base_app(about: &'static str, usage: &str) -> Command { .arg( Arg::new(options::FILE) .index(1) - .action(clap::ArgAction::Append) + .action(ArgAction::Append) .value_hint(clap::ValueHint::FilePath), ) } diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index af228b142..a40fcc185 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -90,7 +90,7 @@ pub fn uu_app() -> Command { ) .arg( Arg::new(options::NAME) - .action(clap::ArgAction::Append) + .action(ArgAction::Append) .value_hint(clap::ValueHint::AnyPath) .hide(true) .trailing_var_arg(true), diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index 185733da5..c86718e11 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -86,7 +86,7 @@ impl LineNumber { } } - fn write(&self, writer: &mut impl Write) -> std::io::Result<()> { + fn write(&self, writer: &mut impl Write) -> io::Result<()> { writer.write_all(&self.buf) } } @@ -288,7 +288,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::FILE) .hide(true) - .action(clap::ArgAction::Append) + .action(ArgAction::Append) .value_hint(clap::ValueHint::FilePath), ) .arg( @@ -377,7 +377,7 @@ fn cat_handle( /// Whether this process is appending to stdout. #[cfg(unix)] fn is_appending() -> bool { - let stdout = std::io::stdout(); + let stdout = io::stdout(); let flags = match fcntl(stdout.as_raw_fd(), FcntlArg::F_GETFL) { Ok(flags) => flags, Err(_) => return false, @@ -404,7 +404,7 @@ fn cat_path( let in_info = FileInformation::from_file(&stdin)?; let mut handle = InputHandle { reader: stdin, - is_interactive: std::io::stdin().is_terminal(), + is_interactive: io::stdin().is_terminal(), }; if let Some(out_info) = out_info { if in_info == *out_info && is_appending() { @@ -445,7 +445,7 @@ fn cat_path( } fn cat_files(files: &[String], options: &OutputOptions) -> UResult<()> { - let out_info = FileInformation::from_file(&std::io::stdout()).ok(); + let out_info = FileInformation::from_file(&io::stdout()).ok(); let mut state = OutputState { line_number: LineNumber::new(), diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index 1ef22f0fd..5c7671c87 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -312,7 +312,7 @@ struct Options { files: Vec, } -fn parse_command_line(config: clap::Command, args: impl uucore::Args) -> Result { +fn parse_command_line(config: Command, args: impl uucore::Args) -> Result { let matches = config.try_get_matches_from(args)?; let verbose = matches.get_flag(options::VERBOSE); diff --git a/src/uu/chcon/src/fts.rs b/src/uu/chcon/src/fts.rs index 30650fbf5..a737b5f26 100644 --- a/src/uu/chcon/src/fts.rs +++ b/src/uu/chcon/src/fts.rs @@ -16,9 +16,9 @@ use crate::os_str_to_c_string; #[derive(Debug)] pub(crate) struct FTS { - fts: ptr::NonNull, + fts: NonNull, - entry: Option>, + entry: Option>, _phantom_data: PhantomData, } @@ -52,7 +52,7 @@ impl FTS { // - `compar` is None. let fts = unsafe { fts_sys::fts_open(path_argv.as_ptr().cast(), options, None) }; - let fts = ptr::NonNull::new(fts) + let fts = NonNull::new(fts) .ok_or_else(|| Error::from_io("fts_open()", io::Error::last_os_error()))?; Ok(Self { @@ -110,14 +110,14 @@ impl Drop for FTS { #[derive(Debug)] pub(crate) struct EntryRef<'fts> { - pub(crate) pointer: ptr::NonNull, + pub(crate) pointer: NonNull, _fts: PhantomData<&'fts FTS>, _phantom_data: PhantomData, } impl<'fts> EntryRef<'fts> { - fn new(_fts: &'fts FTS, entry: ptr::NonNull) -> Self { + fn new(_fts: &'fts FTS, entry: NonNull) -> Self { Self { pointer: entry, _fts: PhantomData, @@ -174,7 +174,7 @@ impl<'fts> EntryRef<'fts> { } pub(crate) fn access_path(&self) -> Option<&Path> { - ptr::NonNull::new(self.as_ref().fts_accpath) + NonNull::new(self.as_ref().fts_accpath) .map(|path_ptr| { // SAFETY: `entry.fts_accpath` is a non-null pointer that is assumed to be valid. unsafe { CStr::from_ptr(path_ptr.as_ptr()) } @@ -184,7 +184,7 @@ impl<'fts> EntryRef<'fts> { } pub(crate) fn stat(&self) -> Option<&libc::stat> { - ptr::NonNull::new(self.as_ref().fts_statp).map(|stat_ptr| { + NonNull::new(self.as_ref().fts_statp).map(|stat_ptr| { // SAFETY: `entry.fts_statp` is a non-null pointer that is assumed to be valid. unsafe { stat_ptr.as_ref() } }) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 3617dd6e4..a1a9115d9 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -350,7 +350,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::FILE) .hide(true) - .action(clap::ArgAction::Append) + .action(ArgAction::Append) .value_parser(ValueParser::os_string()) .value_hint(clap::ValueHint::FilePath), ) diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index f0944ff6e..6df8b1301 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -118,8 +118,8 @@ impl OrderChecker { // Check if two files are identical by comparing their contents pub fn are_files_identical(path1: &str, path2: &str) -> io::Result { // First compare file sizes - let metadata1 = std::fs::metadata(path1)?; - let metadata2 = std::fs::metadata(path2)?; + let metadata1 = metadata(path1)?; + let metadata2 = metadata(path2)?; if metadata1.len() != metadata2.len() { return Ok(false); diff --git a/src/uu/cp/src/copydir.rs b/src/uu/cp/src/copydir.rs index 87cd980be..40b5456db 100644 --- a/src/uu/cp/src/copydir.rs +++ b/src/uu/cp/src/copydir.rs @@ -101,7 +101,7 @@ struct Context<'a> { } impl<'a> Context<'a> { - fn new(root: &'a Path, target: &'a Path) -> std::io::Result { + fn new(root: &'a Path, target: &'a Path) -> io::Result { let current_dir = env::current_dir()?; let root_path = current_dir.join(root); let root_parent = if target.exists() && !root.to_str().unwrap().ends_with("/.") { @@ -181,7 +181,7 @@ impl Entry { if no_target_dir { let source_is_dir = source.is_dir(); if path_ends_with_terminator(context.target) && source_is_dir { - if let Err(e) = std::fs::create_dir_all(context.target) { + if let Err(e) = fs::create_dir_all(context.target) { eprintln!("Failed to create directory: {e}"); } } else { @@ -305,9 +305,7 @@ fn copy_direntry( false, ) { Ok(_) => {} - Err(Error::IoErrContext(e, _)) - if e.kind() == std::io::ErrorKind::PermissionDenied => - { + Err(Error::IoErrContext(e, _)) if e.kind() == io::ErrorKind::PermissionDenied => { show!(uio_error!( e, "cannot open {} for reading", @@ -580,14 +578,13 @@ fn build_dir( // we need to allow trivial casts here because some systems like linux have u32 constants in // in libc while others don't. #[allow(clippy::unnecessary_cast)] - let mut excluded_perms = - if matches!(options.attributes.ownership, crate::Preserve::Yes { .. }) { - libc::S_IRWXG | libc::S_IRWXO // exclude rwx for group and other - } else if matches!(options.attributes.mode, crate::Preserve::Yes { .. }) { - libc::S_IWGRP | libc::S_IWOTH //exclude w for group and other - } else { - 0 - } as u32; + let mut excluded_perms = if matches!(options.attributes.ownership, Preserve::Yes { .. }) { + libc::S_IRWXG | libc::S_IRWXO // exclude rwx for group and other + } else if matches!(options.attributes.mode, Preserve::Yes { .. }) { + libc::S_IWGRP | libc::S_IWOTH //exclude w for group and other + } else { + 0 + } as u32; let umask = if copy_attributes_from.is_some() && matches!(options.attributes.mode, Preserve::Yes { .. }) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index b85f3c8d8..4c294ba16 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -737,7 +737,7 @@ pub fn uu_app() -> Command { Arg::new(options::PROGRESS_BAR) .long(options::PROGRESS_BAR) .short('g') - .action(clap::ArgAction::SetTrue) + .action(ArgAction::SetTrue) .help( "Display a progress bar. \n\ Note: this feature is not supported by GNU coreutils.", @@ -2081,7 +2081,7 @@ fn handle_copy_mode( CopyMode::Update => { if dest.exists() { match options.update { - update_control::UpdateMode::ReplaceAll => { + UpdateMode::ReplaceAll => { copy_helper( source, dest, @@ -2094,17 +2094,17 @@ fn handle_copy_mode( source_is_stream, )?; } - update_control::UpdateMode::ReplaceNone => { + UpdateMode::ReplaceNone => { if options.debug { println!("skipped {}", dest.quote()); } return Ok(PerformedAction::Skipped); } - update_control::UpdateMode::ReplaceNoneFail => { + UpdateMode::ReplaceNoneFail => { return Err(Error::Error(format!("not replacing '{}'", dest.display()))); } - update_control::UpdateMode::ReplaceIfOlder => { + UpdateMode::ReplaceIfOlder => { let dest_metadata = fs::symlink_metadata(dest)?; let src_time = source_metadata.modified()?; @@ -2335,7 +2335,7 @@ fn copy_file( &FileInformation::from_path(source, options.dereference(source_in_command_line)) .context(format!("cannot stat {}", source.quote()))?, ) { - std::fs::hard_link(new_source, dest)?; + fs::hard_link(new_source, dest)?; if options.verbose { print_verbose_output(options.parents, progress_bar, source, dest); diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 4b33a45a7..fc99a759f 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -43,7 +43,7 @@ mod options { /// Command line options for csplit. pub struct CsplitOptions { - split_name: crate::SplitName, + split_name: SplitName, keep_files: bool, quiet: bool, elide_empty_files: bool, @@ -661,7 +661,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::PATTERN) .hide(true) - .action(clap::ArgAction::Append) + .action(ArgAction::Append) .required(true), ) .after_help(AFTER_HELP) diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 8e31dbda7..49f5445f3 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -352,7 +352,7 @@ fn cut_files(mut filenames: Vec, mode: &Mode) { filenames.push("-".to_owned()); } - let mut out: Box = if std::io::stdout().is_terminal() { + let mut out: Box = if stdout().is_terminal() { Box::new(stdout()) } else { Box::new(BufWriter::new(stdout())) as Box diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index fcbca0dd5..29677ddbe 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -222,7 +222,7 @@ impl Source { /// The length of the data source in number of bytes. /// /// If it cannot be determined, then this function returns 0. - fn len(&self) -> std::io::Result { + fn len(&self) -> io::Result { match self { Self::File(f) => Ok(f.metadata()?.len().try_into().unwrap_or(i64::MAX)), _ => Ok(0), @@ -260,7 +260,7 @@ impl Source { Err(e) => Err(e), } } - Self::File(f) => f.seek(io::SeekFrom::Current(n.try_into().unwrap())), + Self::File(f) => f.seek(SeekFrom::Current(n.try_into().unwrap())), #[cfg(unix)] Self::Fifo(f) => io::copy(&mut f.take(n), &mut io::sink()), } @@ -470,7 +470,7 @@ impl Input<'_> { /// Fills a given buffer. /// Reads in increments of 'self.ibs'. /// The start of each ibs-sized read follows the previous one. - fn fill_consecutive(&mut self, buf: &mut Vec) -> std::io::Result { + fn fill_consecutive(&mut self, buf: &mut Vec) -> io::Result { let mut reads_complete = 0; let mut reads_partial = 0; let mut bytes_total = 0; @@ -501,7 +501,7 @@ impl Input<'_> { /// Fills a given buffer. /// Reads in increments of 'self.ibs'. /// The start of each ibs-sized read is aligned to multiples of ibs; remaining space is filled with the 'pad' byte. - fn fill_blocks(&mut self, buf: &mut Vec, pad: u8) -> std::io::Result { + fn fill_blocks(&mut self, buf: &mut Vec, pad: u8) -> io::Result { let mut reads_complete = 0; let mut reads_partial = 0; let mut base_idx = 0; @@ -612,7 +612,7 @@ impl Dest { return Ok(len); } } - f.seek(io::SeekFrom::Current(n.try_into().unwrap())) + f.seek(SeekFrom::Current(n.try_into().unwrap())) } #[cfg(unix)] Self::Fifo(f) => { @@ -655,7 +655,7 @@ impl Dest { /// The length of the data destination in number of bytes. /// /// If it cannot be determined, then this function returns 0. - fn len(&self) -> std::io::Result { + fn len(&self) -> io::Result { match self { Self::File(f, _) => Ok(f.metadata()?.len().try_into().unwrap_or(i64::MAX)), _ => Ok(0), @@ -676,7 +676,7 @@ impl Write for Dest { .len() .try_into() .expect("Internal dd Error: Seek amount greater than signed 64-bit integer"); - f.seek(io::SeekFrom::Current(seek_amt))?; + f.seek(SeekFrom::Current(seek_amt))?; Ok(buf.len()) } Self::File(f, _) => f.write(buf), @@ -893,7 +893,7 @@ impl<'a> Output<'a> { } /// Flush the output to disk, if configured to do so. - fn sync(&mut self) -> std::io::Result<()> { + fn sync(&mut self) -> io::Result<()> { if self.settings.oconv.fsync { self.dst.fsync() } else if self.settings.oconv.fdatasync { @@ -905,7 +905,7 @@ impl<'a> Output<'a> { } /// Truncate the underlying file to the current stream position, if possible. - fn truncate(&mut self) -> std::io::Result<()> { + fn truncate(&mut self) -> io::Result<()> { self.dst.truncate() } } @@ -959,7 +959,7 @@ impl BlockWriter<'_> { }; } - fn write_blocks(&mut self, buf: &[u8]) -> std::io::Result { + fn write_blocks(&mut self, buf: &[u8]) -> io::Result { match self { Self::Unbuffered(o) => o.write_blocks(buf), Self::Buffered(o) => o.write_blocks(buf), @@ -969,7 +969,7 @@ impl BlockWriter<'_> { /// depending on the command line arguments, this function /// informs the OS to flush/discard the caches for input and/or output file. -fn flush_caches_full_length(i: &Input, o: &Output) -> std::io::Result<()> { +fn flush_caches_full_length(i: &Input, o: &Output) -> io::Result<()> { // TODO Better error handling for overflowing `len`. if i.settings.iflags.nocache { let offset = 0; @@ -1001,7 +1001,7 @@ fn flush_caches_full_length(i: &Input, o: &Output) -> std::io::Result<()> { /// /// If there is a problem reading from the input or writing to /// this output. -fn dd_copy(mut i: Input, o: Output) -> std::io::Result<()> { +fn dd_copy(mut i: Input, o: Output) -> io::Result<()> { // The read and write statistics. // // These objects are counters, initialized to zero. After each @@ -1177,7 +1177,7 @@ fn finalize( prog_tx: &mpsc::Sender, output_thread: thread::JoinHandle, truncate: bool, -) -> std::io::Result<()> { +) -> io::Result<()> { // Flush the output in case a partial write has been buffered but // not yet written. let wstat_update = output.flush()?; @@ -1245,7 +1245,7 @@ fn make_linux_oflags(oflags: &OFlags) -> Option { /// `conv=swab` or `conv=block` command-line arguments. This function /// mutates the `buf` argument in-place. The returned [`ReadStat`] /// indicates how many blocks were read. -fn read_helper(i: &mut Input, buf: &mut Vec, bsize: usize) -> std::io::Result { +fn read_helper(i: &mut Input, buf: &mut Vec, bsize: usize) -> io::Result { // Local Helper Fns ------------------------------------------------- fn perform_swab(buf: &mut [u8]) { for base in (1..buf.len()).step_by(2) { diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index ec46b2080..89a0e56b5 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -654,7 +654,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { files.collect() } else { // Deduplicate while preserving order - let mut seen = std::collections::HashSet::new(); + let mut seen = HashSet::new(); files .filter(|path| seen.insert(path.clone())) .collect::>() diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 98f46fc9d..f17d70ed6 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -345,7 +345,7 @@ fn debug_print_args(args: &[OsString]) { fn check_and_handle_string_args( arg: &OsString, prefix_to_test: &str, - all_args: &mut Vec, + all_args: &mut Vec, do_debug_print_args: Option<&Vec>, ) -> UResult { let native_arg = NCvt::convert(arg); @@ -386,8 +386,8 @@ impl EnvAppData { fn process_all_string_arguments( &mut self, original_args: &Vec, - ) -> UResult> { - let mut all_args: Vec = Vec::new(); + ) -> UResult> { + let mut all_args: Vec = Vec::new(); for arg in original_args { match arg { b if check_and_handle_string_args(b, "--split-string", &mut all_args, None)? => { @@ -454,7 +454,7 @@ impl EnvAppData { uucore::show_error!("{s}"); } uucore::show_error!("{ERROR_MSG_S_SHEBANG}"); - uucore::error::ExitCode::new(125) + ExitCode::new(125) } } })?; @@ -751,7 +751,7 @@ fn apply_ignore_signal(opts: &Options<'_>) -> UResult<()> { for &sig_value in &opts.ignore_signal { let sig: Signal = (sig_value as i32) .try_into() - .map_err(|e| std::io::Error::from_raw_os_error(e as i32))?; + .map_err(|e| io::Error::from_raw_os_error(e as i32))?; ignore_signal(sig)?; } @@ -786,7 +786,7 @@ mod tests { #[test] fn test_split_string_environment_vars_test() { - unsafe { std::env::set_var("FOO", "BAR") }; + unsafe { env::set_var("FOO", "BAR") }; assert_eq!( NCvt::convert(vec!["FOO=bar", "sh", "-c", "echo xBARx =$FOO="]), parse_args_from_str(&NCvt::convert(r#"FOO=bar sh -c "echo x${FOO}x =\$FOO=""#)) diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index c389cc187..2c8d1661c 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -27,10 +27,10 @@ mod options { fn print_factors_str( num_str: &str, - w: &mut io::BufWriter, + w: &mut io::BufWriter, print_exponents: bool, ) -> UResult<()> { - let rx = num_str.trim().parse::(); + let rx = num_str.trim().parse::(); let Ok(x) = rx else { // return Ok(). it's non-fatal and we should try the next number. show_warning!("{}: {}", num_str.maybe_quote(), rx.unwrap_err()); diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index b293d9a3f..9d2a841db 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -7,7 +7,6 @@ use clap::{Arg, ArgAction, ArgMatches, Command}; use std::ffi::OsString; -#[cfg(unix)] use std::fs::File; use std::io::{self, BufWriter, Read, Seek, SeekFrom, Write}; use std::num::TryFromIntError; @@ -224,7 +223,7 @@ struct HeadOptions { impl HeadOptions { ///Construct options from matches - pub fn get_from(matches: &clap::ArgMatches) -> Result { + pub fn get_from(matches: &ArgMatches) -> Result { let mut options = Self::default(); options.quiet = matches.get_flag(options::QUIET_NAME); @@ -251,12 +250,12 @@ fn wrap_in_stdout_error(err: io::Error) -> io::Error { ) } -fn read_n_bytes(input: impl Read, n: u64) -> std::io::Result { +fn read_n_bytes(input: impl Read, n: u64) -> io::Result { // Read the first `n` bytes from the `input` reader. let mut reader = input.take(n); // Write those bytes to `stdout`. - let stdout = std::io::stdout(); + let stdout = io::stdout(); let mut stdout = stdout.lock(); let bytes_written = io::copy(&mut reader, &mut stdout).map_err(wrap_in_stdout_error)?; @@ -269,12 +268,12 @@ fn read_n_bytes(input: impl Read, n: u64) -> std::io::Result { Ok(bytes_written) } -fn read_n_lines(input: &mut impl std::io::BufRead, n: u64, separator: u8) -> std::io::Result { +fn read_n_lines(input: &mut impl io::BufRead, n: u64, separator: u8) -> io::Result { // Read the first `n` lines from the `input` reader. let mut reader = take_lines(input, n, separator); // Write those bytes to `stdout`. - let stdout = std::io::stdout(); + let stdout = io::stdout(); let stdout = stdout.lock(); let mut writer = BufWriter::with_capacity(BUF_SIZE, stdout); @@ -298,10 +297,10 @@ fn catch_too_large_numbers_in_backwards_bytes_or_lines(n: u64) -> Option } } -fn read_but_last_n_bytes(mut input: impl Read, n: u64) -> std::io::Result { +fn read_but_last_n_bytes(mut input: impl Read, n: u64) -> io::Result { let mut bytes_written: u64 = 0; if let Some(n) = catch_too_large_numbers_in_backwards_bytes_or_lines(n) { - let stdout = std::io::stdout(); + let stdout = io::stdout(); let mut stdout = stdout.lock(); bytes_written = copy_all_but_n_bytes(&mut input, &mut stdout, n) @@ -317,8 +316,8 @@ fn read_but_last_n_bytes(mut input: impl Read, n: u64) -> std::io::Result { Ok(bytes_written) } -fn read_but_last_n_lines(mut input: impl Read, n: u64, separator: u8) -> std::io::Result { - let stdout = std::io::stdout(); +fn read_but_last_n_lines(mut input: impl Read, n: u64, separator: u8) -> io::Result { + let stdout = io::stdout(); let mut stdout = stdout.lock(); if n == 0 { return io::copy(&mut input, &mut stdout).map_err(wrap_in_stdout_error); @@ -370,7 +369,7 @@ fn read_but_last_n_lines(mut input: impl Read, n: u64, separator: u8) -> std::io /// assert_eq!(find_nth_line_from_end(&mut input, 4, false).unwrap(), 0); /// assert_eq!(find_nth_line_from_end(&mut input, 1000, false).unwrap(), 0); /// ``` -fn find_nth_line_from_end(input: &mut R, n: u64, separator: u8) -> std::io::Result +fn find_nth_line_from_end(input: &mut R, n: u64, separator: u8) -> io::Result where R: Read + Seek, { @@ -408,14 +407,14 @@ where } } -fn is_seekable(input: &mut std::fs::File) -> bool { +fn is_seekable(input: &mut File) -> bool { let current_pos = input.stream_position(); current_pos.is_ok() && input.seek(SeekFrom::End(0)).is_ok() && input.seek(SeekFrom::Start(current_pos.unwrap())).is_ok() } -fn head_backwards_file(input: &mut std::fs::File, options: &HeadOptions) -> std::io::Result { +fn head_backwards_file(input: &mut File, options: &HeadOptions) -> io::Result { let st = input.metadata()?; let seekable = is_seekable(input); let blksize_limit = uucore::fs::sane_blksize::sane_blksize_from_metadata(&st); @@ -426,10 +425,7 @@ fn head_backwards_file(input: &mut std::fs::File, options: &HeadOptions) -> std: } } -fn head_backwards_without_seek_file( - input: &mut std::fs::File, - options: &HeadOptions, -) -> std::io::Result { +fn head_backwards_without_seek_file(input: &mut File, options: &HeadOptions) -> io::Result { match options.mode { Mode::AllButLastBytes(n) => read_but_last_n_bytes(input, n), Mode::AllButLastLines(n) => read_but_last_n_lines(input, n, options.line_ending.into()), @@ -437,10 +433,7 @@ fn head_backwards_without_seek_file( } } -fn head_backwards_on_seekable_file( - input: &mut std::fs::File, - options: &HeadOptions, -) -> std::io::Result { +fn head_backwards_on_seekable_file(input: &mut File, options: &HeadOptions) -> io::Result { match options.mode { Mode::AllButLastBytes(n) => { let size = input.metadata()?.len(); @@ -458,11 +451,11 @@ fn head_backwards_on_seekable_file( } } -fn head_file(input: &mut std::fs::File, options: &HeadOptions) -> std::io::Result { +fn head_file(input: &mut File, options: &HeadOptions) -> io::Result { match options.mode { Mode::FirstBytes(n) => read_n_bytes(input, n), Mode::FirstLines(n) => read_n_lines( - &mut std::io::BufReader::with_capacity(BUF_SIZE, input), + &mut io::BufReader::with_capacity(BUF_SIZE, input), n, options.line_ending.into(), ), @@ -482,7 +475,7 @@ fn uu_head(options: &HeadOptions) -> UResult<()> { } println!("==> standard input <=="); } - let stdin = std::io::stdin(); + let stdin = io::stdin(); #[cfg(unix)] { @@ -520,7 +513,7 @@ fn uu_head(options: &HeadOptions) -> UResult<()> { Ok(()) } (name, false) => { - let mut file = match std::fs::File::open(name) { + let mut file = match File::open(name) { Ok(f) => f, Err(err) => { show!(err.map_err_context(|| format!( @@ -575,8 +568,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { #[cfg(test)] mod tests { + use io::Cursor; use std::ffi::OsString; - use std::io::Cursor; use super::*; @@ -691,7 +684,7 @@ mod tests { #[test] fn read_early_exit() { - let mut empty = std::io::BufReader::new(std::io::Cursor::new(Vec::new())); + let mut empty = io::BufReader::new(Cursor::new(Vec::new())); assert!(read_n_bytes(&mut empty, 0).is_ok()); assert!(read_n_lines(&mut empty, 0, b'\n').is_ok()); } diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index cd4487b91..d890cdf58 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -675,7 +675,7 @@ fn chown_optional_user_group(path: &Path, b: &Behavior) -> UResult<()> { return Ok(()); }; - let meta = match fs::metadata(path) { + let meta = match metadata(path) { Ok(meta) => meta, Err(e) => return Err(InstallError::MetadataFailed(e).into()), }; @@ -859,7 +859,7 @@ fn set_ownership_and_permissions(to: &Path, b: &Behavior) -> UResult<()> { /// Returns an empty Result or an error in case of failure. /// fn preserve_timestamps(from: &Path, to: &Path) -> UResult<()> { - let meta = match fs::metadata(from) { + let meta = match metadata(from) { Ok(meta) => meta, Err(e) => return Err(InstallError::MetadataFailed(e).into()), }; @@ -940,14 +940,14 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> { fn need_copy(from: &Path, to: &Path, b: &Behavior) -> UResult { // Attempt to retrieve metadata for the source file. // If this fails, assume the file needs to be copied. - let from_meta = match fs::metadata(from) { + let from_meta = match metadata(from) { Ok(meta) => meta, Err(_) => return Ok(true), }; // Attempt to retrieve metadata for the destination file. // If this fails, assume the file needs to be copied. - let to_meta = match fs::metadata(to) { + let to_meta = match metadata(to) { Ok(meta) => meta, Err(_) => return Ok(true), }; diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index f5c3a3627..8d8aa0b61 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -74,7 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } else { let sig = (sig as i32) .try_into() - .map_err(|e| std::io::Error::from_raw_os_error(e as i32))?; + .map_err(|e| Error::from_raw_os_error(e as i32))?; Some(sig) }; diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a64636c49..8f6abbd34 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -439,7 +439,7 @@ fn extract_format(options: &clap::ArgMatches) -> (Format, Option<&'static str>) (Format::Commas, Some(options::format::COMMAS)) } else if options.get_flag(options::format::COLUMNS) { (Format::Columns, Some(options::format::COLUMNS)) - } else if std::io::stdout().is_terminal() { + } else if stdout().is_terminal() { (Format::Columns, None) } else { (Format::OneLine, None) @@ -559,7 +559,7 @@ fn extract_color(options: &clap::ArgMatches) -> bool { None => options.contains_id(options::COLOR), Some(val) => match val.as_str() { "" | "always" | "yes" | "force" => true, - "auto" | "tty" | "if-tty" => std::io::stdout().is_terminal(), + "auto" | "tty" | "if-tty" => stdout().is_terminal(), /* "never" | "no" | "none" | */ _ => false, }, } @@ -578,7 +578,7 @@ fn extract_hyperlink(options: &clap::ArgMatches) -> bool { match hyperlink { "always" | "yes" | "force" => true, - "auto" | "tty" | "if-tty" => std::io::stdout().is_terminal(), + "auto" | "tty" | "if-tty" => stdout().is_terminal(), "never" | "no" | "none" => false, _ => unreachable!("should be handled by clap"), } @@ -673,7 +673,7 @@ fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> Quot // By default, `ls` uses Shell escape quoting style when writing to a terminal file // descriptor and Literal otherwise. - if std::io::stdout().is_terminal() { + if stdout().is_terminal() { QuotingStyle::Shell { escape: true, always_quote: false, @@ -704,7 +704,7 @@ fn extract_indicator_style(options: &clap::ArgMatches) -> IndicatorStyle { "never" | "no" | "none" => IndicatorStyle::None, "always" | "yes" | "force" => IndicatorStyle::Classify, "auto" | "tty" | "if-tty" => { - if std::io::stdout().is_terminal() { + if stdout().is_terminal() { IndicatorStyle::Classify } else { IndicatorStyle::None @@ -933,7 +933,7 @@ impl Config { } else if options.get_flag(options::SHOW_CONTROL_CHARS) { true } else { - !std::io::stdout().is_terminal() + !stdout().is_terminal() }; let mut quoting_style = extract_quoting_style(options, show_control); @@ -2386,7 +2386,7 @@ fn get_metadata_with_deref_opt(p_buf: &Path, dereference: bool) -> std::io::Resu fn display_dir_entry_size( entry: &PathData, config: &Config, - out: &mut BufWriter, + out: &mut BufWriter, ) -> (usize, usize, usize, usize, usize, usize) { // TODO: Cache/memorize the display_* results so we don't have to recalculate them. if let Some(md) = entry.get_metadata(out) { @@ -3070,7 +3070,7 @@ fn get_system_time(md: &Metadata, config: &Config) -> Option { } } -fn get_time(md: &Metadata, config: &Config) -> Option> { +fn get_time(md: &Metadata, config: &Config) -> Option> { let time = get_system_time(md, config)?; Some(time.into()) } diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index ce460bcc8..cde2db13d 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -266,7 +266,7 @@ pub fn uu_app() -> Command { } #[cfg(not(target_os = "fuchsia"))] -fn setup_term() -> std::io::Stdout { +fn setup_term() -> Stdout { let stdout = stdout(); terminal::enable_raw_mode().unwrap(); stdout @@ -279,10 +279,10 @@ fn setup_term() -> usize { } #[cfg(not(target_os = "fuchsia"))] -fn reset_term(stdout: &mut std::io::Stdout) { +fn reset_term(stdout: &mut Stdout) { terminal::disable_raw_mode().unwrap(); // Clear the prompt - queue!(stdout, terminal::Clear(ClearType::CurrentLine)).unwrap(); + queue!(stdout, Clear(ClearType::CurrentLine)).unwrap(); // Move cursor to the beginning without printing new line print!("\r"); stdout.flush().unwrap(); @@ -313,7 +313,7 @@ fn more( match search_pattern_in_file(&pager.lines, pat) { Some(number) => pager.upper_mark = number, None => { - execute!(stdout, terminal::Clear(terminal::ClearType::CurrentLine))?; + execute!(stdout, Clear(ClearType::CurrentLine))?; stdout.write_all("\rPattern not found\n".as_bytes())?; pager.content_rows -= 1; } @@ -321,7 +321,7 @@ fn more( } if multiple_file { - execute!(stdout, terminal::Clear(terminal::ClearType::CurrentLine)).unwrap(); + execute!(stdout, Clear(ClearType::CurrentLine)).unwrap(); stdout.write_all( MULTI_FILE_TOP_PROMPT .replace("{}", file.unwrap_or_default()) @@ -516,7 +516,7 @@ impl<'a> Pager<'a> { }; } - fn draw(&mut self, stdout: &mut std::io::Stdout, wrong_key: Option) { + fn draw(&mut self, stdout: &mut Stdout, wrong_key: Option) { self.draw_lines(stdout); let lower_mark = self .line_count @@ -525,8 +525,8 @@ impl<'a> Pager<'a> { stdout.flush().unwrap(); } - fn draw_lines(&mut self, stdout: &mut std::io::Stdout) { - execute!(stdout, terminal::Clear(terminal::ClearType::CurrentLine)).unwrap(); + fn draw_lines(&mut self, stdout: &mut Stdout) { + execute!(stdout, Clear(ClearType::CurrentLine)).unwrap(); self.line_squeezed = 0; let mut previous_line_blank = false; @@ -611,7 +611,7 @@ fn search_pattern_in_file(lines: &[&str], pattern: &str) -> Option { None } -fn paging_add_back_message(options: &Options, stdout: &mut std::io::Stdout) -> UResult<()> { +fn paging_add_back_message(options: &Options, stdout: &mut Stdout) -> UResult<()> { if options.lines.is_some() { execute!(stdout, MoveUp(1))?; stdout.write_all("\n\r...back 1 page\n".as_bytes())?; diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index cd6fe8141..73003a164 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -131,7 +131,7 @@ fn replace_fds() -> UResult<()> { } fn find_stdout() -> UResult { - let internal_failure_code = match std::env::var("POSIXLY_CORRECT") { + let internal_failure_code = match env::var("POSIXLY_CORRECT") { Ok(_) => POSIX_NOHUP_FAILURE, Err(_) => EXIT_CANCELED, }; diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index bea0c73cf..ecbdc94f3 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -153,10 +153,10 @@ fn parse_unit_size_suffix(s: &str) -> Option { } fn parse_options(args: &ArgMatches) -> Result { - let from = parse_unit(args.get_one::(options::FROM).unwrap())?; - let to = parse_unit(args.get_one::(options::TO).unwrap())?; - let from_unit = parse_unit_size(args.get_one::(options::FROM_UNIT).unwrap())?; - let to_unit = parse_unit_size(args.get_one::(options::TO_UNIT).unwrap())?; + let from = parse_unit(args.get_one::(FROM).unwrap())?; + let to = parse_unit(args.get_one::(TO).unwrap())?; + let from_unit = parse_unit_size(args.get_one::(FROM_UNIT).unwrap())?; + let to_unit = parse_unit_size(args.get_one::(TO_UNIT).unwrap())?; let transform = TransformOptions { from, @@ -165,7 +165,7 @@ fn parse_options(args: &ArgMatches) -> Result { to_unit, }; - let padding = match args.get_one::(options::PADDING) { + let padding = match args.get_one::(PADDING) { Some(s) => s .parse::() .map_err(|_| s) @@ -177,8 +177,8 @@ fn parse_options(args: &ArgMatches) -> Result { None => Ok(0), }?; - let header = if args.value_source(options::HEADER) == Some(ValueSource::CommandLine) { - let value = args.get_one::(options::HEADER).unwrap(); + let header = if args.value_source(HEADER) == Some(ValueSource::CommandLine) { + let value = args.get_one::(HEADER).unwrap(); value .parse::() @@ -192,7 +192,7 @@ fn parse_options(args: &ArgMatches) -> Result { Ok(0) }?; - let fields = args.get_one::(options::FIELD).unwrap().as_str(); + let fields = args.get_one::(FIELD).unwrap().as_str(); // a lone "-" means "all fields", even as part of a list of fields let fields = if fields.split(&[',', ' ']).any(|x| x == "-") { vec![Range { @@ -203,7 +203,7 @@ fn parse_options(args: &ArgMatches) -> Result { Range::from_list(fields)? }; - let format = match args.get_one::(options::FORMAT) { + let format = match args.get_one::(FORMAT) { Some(s) => s.parse()?, None => FormatOptions::default(), }; @@ -212,18 +212,16 @@ fn parse_options(args: &ArgMatches) -> Result { return Err("grouping cannot be combined with --to".to_string()); } - let delimiter = args - .get_one::(options::DELIMITER) - .map_or(Ok(None), |arg| { - if arg.len() == 1 { - Ok(Some(arg.to_string())) - } else { - Err("the delimiter must be a single character".to_string()) - } - })?; + let delimiter = args.get_one::(DELIMITER).map_or(Ok(None), |arg| { + if arg.len() == 1 { + Ok(Some(arg.to_string())) + } else { + Err("the delimiter must be a single character".to_string()) + } + })?; // unwrap is fine because the argument has a default value - let round = match args.get_one::(options::ROUND).unwrap().as_str() { + let round = match args.get_one::(ROUND).unwrap().as_str() { "up" => RoundMethod::Up, "down" => RoundMethod::Down, "from-zero" => RoundMethod::FromZero, @@ -232,10 +230,9 @@ fn parse_options(args: &ArgMatches) -> Result { _ => unreachable!("Should be restricted by clap"), }; - let suffix = args.get_one::(options::SUFFIX).cloned(); + let suffix = args.get_one::(SUFFIX).cloned(); - let invalid = - InvalidModes::from_str(args.get_one::(options::INVALID).unwrap()).unwrap(); + let invalid = InvalidModes::from_str(args.get_one::(INVALID).unwrap()).unwrap(); let zero_terminated = args.get_flag(options::ZERO_TERMINATED); @@ -259,7 +256,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?; - let result = match matches.get_many::(options::NUMBER) { + let result = match matches.get_many::(NUMBER) { Some(values) => handle_args(values.map(|s| s.as_str()), &options), None => { let stdin = std::io::stdin(); @@ -286,58 +283,58 @@ pub fn uu_app() -> Command { .allow_negative_numbers(true) .infer_long_args(true) .arg( - Arg::new(options::DELIMITER) + Arg::new(DELIMITER) .short('d') - .long(options::DELIMITER) + .long(DELIMITER) .value_name("X") .help("use X instead of whitespace for field delimiter"), ) .arg( - Arg::new(options::FIELD) - .long(options::FIELD) + Arg::new(FIELD) + .long(FIELD) .help("replace the numbers in these input fields; see FIELDS below") .value_name("FIELDS") .allow_hyphen_values(true) - .default_value(options::FIELD_DEFAULT), + .default_value(FIELD_DEFAULT), ) .arg( - Arg::new(options::FORMAT) - .long(options::FORMAT) + Arg::new(FORMAT) + .long(FORMAT) .help("use printf style floating-point FORMAT; see FORMAT below for details") .value_name("FORMAT") .allow_hyphen_values(true), ) .arg( - Arg::new(options::FROM) - .long(options::FROM) + Arg::new(FROM) + .long(FROM) .help("auto-scale input numbers to UNITs; see UNIT below") .value_name("UNIT") - .default_value(options::FROM_DEFAULT), + .default_value(FROM_DEFAULT), ) .arg( - Arg::new(options::FROM_UNIT) - .long(options::FROM_UNIT) + Arg::new(FROM_UNIT) + .long(FROM_UNIT) .help("specify the input unit size") .value_name("N") - .default_value(options::FROM_UNIT_DEFAULT), + .default_value(FROM_UNIT_DEFAULT), ) .arg( - Arg::new(options::TO) - .long(options::TO) + Arg::new(TO) + .long(TO) .help("auto-scale output numbers to UNITs; see UNIT below") .value_name("UNIT") - .default_value(options::TO_DEFAULT), + .default_value(TO_DEFAULT), ) .arg( - Arg::new(options::TO_UNIT) - .long(options::TO_UNIT) + Arg::new(TO_UNIT) + .long(TO_UNIT) .help("the output unit size") .value_name("N") - .default_value(options::TO_UNIT_DEFAULT), + .default_value(TO_UNIT_DEFAULT), ) .arg( - Arg::new(options::PADDING) - .long(options::PADDING) + Arg::new(PADDING) + .long(PADDING) .help( "pad the output to N characters; positive N will \ right-align; negative N will left-align; padding is \ @@ -347,20 +344,20 @@ pub fn uu_app() -> Command { .value_name("N"), ) .arg( - Arg::new(options::HEADER) - .long(options::HEADER) + Arg::new(HEADER) + .long(HEADER) .help( "print (without converting) the first N header lines; \ N defaults to 1 if not specified", ) .num_args(..=1) .value_name("N") - .default_missing_value(options::HEADER_DEFAULT) + .default_missing_value(HEADER_DEFAULT) .hide_default_value(true), ) .arg( - Arg::new(options::ROUND) - .long(options::ROUND) + Arg::new(ROUND) + .long(ROUND) .help("use METHOD for rounding when scaling") .value_name("METHOD") .default_value("from-zero") @@ -373,8 +370,8 @@ pub fn uu_app() -> Command { ])), ) .arg( - Arg::new(options::SUFFIX) - .long(options::SUFFIX) + Arg::new(SUFFIX) + .long(SUFFIX) .help( "print SUFFIX after each formatted number, and accept \ inputs optionally ending with SUFFIX", @@ -382,8 +379,8 @@ pub fn uu_app() -> Command { .value_name("SUFFIX"), ) .arg( - Arg::new(options::INVALID) - .long(options::INVALID) + Arg::new(INVALID) + .long(INVALID) .help("set the failure mode for invalid input") .default_value("abort") .value_parser(["abort", "fail", "warn", "ignore"]) @@ -396,11 +393,7 @@ pub fn uu_app() -> Command { .help("line delimiter is NUL, not newline") .action(ArgAction::SetTrue), ) - .arg( - Arg::new(options::NUMBER) - .hide(true) - .action(ArgAction::Append), - ) + .arg(Arg::new(NUMBER).hide(true).action(ArgAction::Append)) } #[cfg(test)] diff --git a/src/uu/od/src/multifilereader.rs b/src/uu/od/src/multifilereader.rs index ec73fed8f..c7d2bbb0a 100644 --- a/src/uu/od/src/multifilereader.rs +++ b/src/uu/od/src/multifilereader.rs @@ -48,7 +48,7 @@ impl MultifileReader<'_> { } match self.ni.remove(0) { InputSource::Stdin => { - self.curr_file = Some(Box::new(BufReader::new(std::io::stdin()))); + self.curr_file = Some(Box::new(BufReader::new(io::stdin()))); break; } InputSource::FileName(fname) => { diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index d78ce01c3..40791529d 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -333,7 +333,7 @@ pub fn remove(files: &[&OsStr], options: &Options) -> bool { /// `path` must be a directory. If there is an error reading the /// contents of the directory, this returns `false`. fn is_dir_empty(path: &Path) -> bool { - match std::fs::read_dir(path) { + match fs::read_dir(path) { Err(_) => false, Ok(iter) => iter.count() == 0, } @@ -348,7 +348,7 @@ fn is_readable_metadata(metadata: &Metadata) -> bool { /// Whether the given file or directory is readable. #[cfg(unix)] fn is_readable(path: &Path) -> bool { - match std::fs::metadata(path) { + match fs::metadata(path) { Err(_) => false, Ok(metadata) => is_readable_metadata(&metadata), } @@ -369,7 +369,7 @@ fn is_writable_metadata(metadata: &Metadata) -> bool { /// Whether the given file or directory is writable. #[cfg(unix)] fn is_writable(path: &Path) -> bool { - match std::fs::metadata(path) { + match fs::metadata(path) { Err(_) => false, Ok(metadata) => is_writable_metadata(&metadata), } @@ -391,7 +391,7 @@ fn is_writable(_path: &Path) -> bool { fn remove_dir_recursive(path: &Path, options: &Options) -> bool { // Special case: if we cannot access the metadata because the // filename is too long, fall back to try - // `std::fs::remove_dir_all()`. + // `fs::remove_dir_all()`. // // TODO This is a temporary bandage; we shouldn't need to do this // at all. Instead of using the full path like "x/y/z", which @@ -400,7 +400,7 @@ fn remove_dir_recursive(path: &Path, options: &Options) -> bool { // path, "z", and know that it is relative to the parent, "x/y". if let Some(s) = path.to_str() { if s.len() > 1000 { - match std::fs::remove_dir_all(path) { + match fs::remove_dir_all(path) { Ok(_) => return false, Err(e) => { let e = e.map_err_context(|| format!("cannot remove {}", path.quote())); @@ -432,7 +432,7 @@ fn remove_dir_recursive(path: &Path, options: &Options) -> bool { // Recursive case: this is a directory. let mut error = false; - match std::fs::read_dir(path) { + match fs::read_dir(path) { Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => { // This is not considered an error. } @@ -456,7 +456,7 @@ fn remove_dir_recursive(path: &Path, options: &Options) -> bool { } // Try removing the directory itself. - match std::fs::remove_dir(path) { + match fs::remove_dir(path) { Err(_) if !error && !is_readable(path) => { // For compatibility with GNU test case // `tests/rm/unread2.sh`, show "Permission denied" in this diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index c70c8685f..8c9dc12b6 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -163,7 +163,7 @@ struct Opts { } pub fn uu_app() -> Command { - Command::new(uucore::util_name()) + Command::new(util_name()) .version(uucore::crate_version!()) .about(ABOUT) .override_usage(format_usage(USAGE)) diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 404d96034..10c6b5ef9 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -152,7 +152,7 @@ pub fn uu_app() -> Command { .short('e') .long(options::ECHO) .help("treat each ARG as an input line") - .action(clap::ArgAction::SetTrue) + .action(ArgAction::SetTrue) .overrides_with(options::ECHO) .conflicts_with(options::INPUT_RANGE), ) @@ -170,7 +170,7 @@ pub fn uu_app() -> Command { .short('n') .long(options::HEAD_COUNT) .value_name("COUNT") - .action(clap::ArgAction::Append) + .action(ArgAction::Append) .help("output at most COUNT lines") .value_parser(usize::from_str), ) @@ -209,7 +209,7 @@ pub fn uu_app() -> Command { ) .arg( Arg::new(options::FILE_OR_ARGS) - .action(clap::ArgAction::Append) + .action(ArgAction::Append) .value_parser(ValueParser::os_string()) .value_hint(clap::ValueHint::FilePath), ) diff --git a/src/uu/sleep/src/sleep.rs b/src/uu/sleep/src/sleep.rs index dcef3f331..0f71c8e55 100644 --- a/src/uu/sleep/src/sleep.rs +++ b/src/uu/sleep/src/sleep.rs @@ -90,7 +90,7 @@ fn sleep(args: &[&str]) -> UResult<()> { } }) .fold(Duration::ZERO, |acc, n| { - acc.saturating_add(SaturatingInto::::saturating_into(n)) + acc.saturating_add(SaturatingInto::::saturating_into(n)) }); if arg_error { diff --git a/src/uu/sort/src/merge.rs b/src/uu/sort/src/merge.rs index a59474021..c7b3a4b0b 100644 --- a/src/uu/sort/src/merge.rs +++ b/src/uu/sort/src/merge.rs @@ -50,7 +50,7 @@ fn replace_output_file_in_input_files( *file = copy.clone().into_os_string(); } else { let (_file, copy_path) = tmp_dir.next_file()?; - std::fs::copy(file_path, ©_path) + fs::copy(file_path, ©_path) .map_err(|error| SortError::OpenTmpFileFailed { error })?; *file = copy_path.clone().into_os_string(); copy = Some(copy_path); diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 280d44777..9673523bd 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1152,7 +1152,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { settings.merge_batch_size = parsed_value; } Err(e) => { - let error_message = if *e.kind() == std::num::IntErrorKind::PosOverflow { + let error_message = if *e.kind() == IntErrorKind::PosOverflow { #[cfg(target_os = "linux")] { show_error!("--batch-size argument {} too large", n_merge.quote()); @@ -1987,7 +1987,7 @@ mod tests { fn test_line_size() { // We should make sure to not regress the size of the Line struct because // it is unconditional overhead for every line we sort. - assert_eq!(std::mem::size_of::(), 24); + assert_eq!(size_of::(), 24); } #[test] diff --git a/src/uu/split/src/number.rs b/src/uu/split/src/number.rs index 6312d0a3f..6de90cfe7 100644 --- a/src/uu/split/src/number.rs +++ b/src/uu/split/src/number.rs @@ -21,8 +21,8 @@ use std::fmt::{self, Display, Formatter}; #[derive(Debug)] pub struct Overflow; -impl fmt::Display for Overflow { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl Display for Overflow { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "Overflow") } } diff --git a/src/uu/split/src/platform/unix.rs b/src/uu/split/src/platform/unix.rs index 3ada2cd1b..3ea3c09f3 100644 --- a/src/uu/split/src/platform/unix.rs +++ b/src/uu/split/src/platform/unix.rs @@ -133,7 +133,7 @@ pub fn instantiate_current_writer( .write(true) .create(true) .truncate(true) - .open(std::path::Path::new(&filename)) + .open(Path::new(&filename)) .map_err(|_| { Error::new( ErrorKind::Other, @@ -144,7 +144,7 @@ pub fn instantiate_current_writer( // re-open file that we previously created to append to it std::fs::OpenOptions::new() .append(true) - .open(std::path::Path::new(&filename)) + .open(Path::new(&filename)) .map_err(|_| { Error::new( ErrorKind::Other, diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index fee77ae07..c3eee8103 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -546,7 +546,7 @@ impl Settings { /// When using `--filter` option, writing to child command process stdin /// could fail with BrokenPipe error /// It can be safely ignored -fn ignorable_io_error(error: &std::io::Error, settings: &Settings) -> bool { +fn ignorable_io_error(error: &io::Error, settings: &Settings) -> bool { error.kind() == ErrorKind::BrokenPipe && settings.filter.is_some() } @@ -555,11 +555,7 @@ fn ignorable_io_error(error: &std::io::Error, settings: &Settings) -> bool { /// If ignorable io error occurs, return number of bytes as if all bytes written /// Should not be used for Kth chunk number sub-strategies /// as those do not work with `--filter` option -fn custom_write( - bytes: &[u8], - writer: &mut T, - settings: &Settings, -) -> std::io::Result { +fn custom_write(bytes: &[u8], writer: &mut T, settings: &Settings) -> io::Result { match writer.write(bytes) { Ok(n) => Ok(n), Err(e) if ignorable_io_error(&e, settings) => Ok(bytes.len()), @@ -576,7 +572,7 @@ fn custom_write_all( bytes: &[u8], writer: &mut T, settings: &Settings, -) -> std::io::Result { +) -> io::Result { match writer.write_all(bytes) { Ok(()) => Ok(true), Err(e) if ignorable_io_error(&e, settings) => Ok(false), @@ -610,7 +606,7 @@ fn get_input_size( reader: &mut R, buf: &mut Vec, io_blksize: &Option, -) -> std::io::Result +) -> io::Result where R: BufRead, { @@ -734,7 +730,7 @@ impl<'a> ByteChunkWriter<'a> { impl Write for ByteChunkWriter<'_> { /// Implements `--bytes=SIZE` - fn write(&mut self, mut buf: &[u8]) -> std::io::Result { + fn write(&mut self, mut buf: &[u8]) -> io::Result { // If the length of `buf` exceeds the number of bytes remaining // in the current chunk, we will need to write to multiple // different underlying writers. In that case, each iteration of @@ -753,7 +749,7 @@ impl Write for ByteChunkWriter<'_> { // Allocate the new file, since at this point we know there are bytes to be written to it. let filename = self.filename_iterator.next().ok_or_else(|| { - std::io::Error::new(ErrorKind::Other, "output file suffixes exhausted") + io::Error::new(ErrorKind::Other, "output file suffixes exhausted") })?; if self.settings.verbose { println!("creating file {}", filename.quote()); @@ -794,7 +790,7 @@ impl Write for ByteChunkWriter<'_> { } } } - fn flush(&mut self) -> std::io::Result<()> { + fn flush(&mut self) -> io::Result<()> { self.inner.flush() } } @@ -858,7 +854,7 @@ impl<'a> LineChunkWriter<'a> { impl Write for LineChunkWriter<'_> { /// Implements `--lines=NUMBER` - fn write(&mut self, buf: &[u8]) -> std::io::Result { + fn write(&mut self, buf: &[u8]) -> io::Result { // If the number of lines in `buf` exceeds the number of lines // remaining in the current chunk, we will need to write to // multiple different underlying writers. In that case, each @@ -874,7 +870,7 @@ impl Write for LineChunkWriter<'_> { if self.num_lines_remaining_in_current_chunk == 0 { self.num_chunks_written += 1; let filename = self.filename_iterator.next().ok_or_else(|| { - std::io::Error::new(ErrorKind::Other, "output file suffixes exhausted") + io::Error::new(ErrorKind::Other, "output file suffixes exhausted") })?; if self.settings.verbose { println!("creating file {}", filename.quote()); @@ -898,7 +894,7 @@ impl Write for LineChunkWriter<'_> { Ok(total_bytes_written) } - fn flush(&mut self) -> std::io::Result<()> { + fn flush(&mut self) -> io::Result<()> { self.inner.flush() } } @@ -1121,7 +1117,7 @@ where } // In Kth chunk of N mode - we will write to stdout instead of to a file. - let mut stdout_writer = std::io::stdout().lock(); + let mut stdout_writer = io::stdout().lock(); // In N chunks mode - we will write to `num_chunks` files let mut out_files: OutFiles = OutFiles::new(); @@ -1247,7 +1243,7 @@ where } // In Kth chunk of N mode - we will write to stdout instead of to a file. - let mut stdout_writer = std::io::stdout().lock(); + let mut stdout_writer = io::stdout().lock(); // In N chunks mode - we will write to `num_chunks` files let mut out_files: OutFiles = OutFiles::new(); @@ -1367,7 +1363,7 @@ where R: BufRead, { // In Kth chunk of N mode - we will write to stdout instead of to a file. - let mut stdout_writer = std::io::stdout().lock(); + let mut stdout_writer = io::stdout().lock(); // In N chunks mode - we will write to `num_chunks` files let mut out_files: OutFiles = OutFiles::new(); @@ -1414,7 +1410,7 @@ where Ok(()) } -/// Like `std::io::Lines`, but includes the line ending character. +/// Like `io::Lines`, but includes the line ending character. /// /// This struct is generally created by calling `lines_with_sep` on a /// reader. @@ -1427,7 +1423,7 @@ impl Iterator for LinesWithSep where R: BufRead, { - type Item = std::io::Result>; + type Item = io::Result>; /// Read bytes from a buffer up to the requested number of lines. fn next(&mut self) -> Option { @@ -1464,8 +1460,7 @@ where // to be overwritten for sure at the beginning of the loop below // because we start with `remaining == 0`, indicating that a new // chunk should start. - let mut writer: BufWriter> = - BufWriter::new(Box::new(std::io::Cursor::new(vec![]))); + let mut writer: BufWriter> = BufWriter::new(Box::new(io::Cursor::new(vec![]))); let mut remaining = 0; for line in lines_with_sep(reader, settings.separator) { @@ -1560,11 +1555,11 @@ fn split(settings: &Settings) -> UResult<()> { } Strategy::Lines(chunk_size) => { let mut writer = LineChunkWriter::new(chunk_size, settings)?; - match std::io::copy(&mut reader, &mut writer) { + match io::copy(&mut reader, &mut writer) { Ok(_) => Ok(()), Err(e) => match e.kind() { // TODO Since the writer object controls the creation of - // new files, we need to rely on the `std::io::Result` + // new files, we need to rely on the `io::Result` // returned by its `write()` method to communicate any // errors to this calling scope. If a new file cannot be // created because we have exceeded the number of @@ -1578,11 +1573,11 @@ fn split(settings: &Settings) -> UResult<()> { } Strategy::Bytes(chunk_size) => { let mut writer = ByteChunkWriter::new(chunk_size, settings)?; - match std::io::copy(&mut reader, &mut writer) { + match io::copy(&mut reader, &mut writer) { Ok(_) => Ok(()), Err(e) => match e.kind() { // TODO Since the writer object controls the creation of - // new files, we need to rely on the `std::io::Result` + // new files, we need to rely on the `io::Result` // returned by its `write()` method to communicate any // errors to this calling scope. If a new file cannot be // created because we have exceeded the number of diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 56a744ea5..6f721cf1d 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -972,8 +972,7 @@ impl Stater { 'Y' => { let sec = meta.mtime(); let nsec = meta.mtime_nsec(); - let tm = - chrono::DateTime::from_timestamp(sec, nsec as u32).unwrap_or_default(); + let tm = DateTime::from_timestamp(sec, nsec as u32).unwrap_or_default(); let tm: DateTime = tm.into(); match tm.timestamp_nanos_opt() { None => { @@ -1186,7 +1185,7 @@ const PRETTY_DATETIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S.%f %z"; fn pretty_time(sec: i64, nsec: i64) -> String { // Return the date in UTC - let tm = chrono::DateTime::from_timestamp(sec, nsec as u32).unwrap_or_default(); + let tm = DateTime::from_timestamp(sec, nsec as u32).unwrap_or_default(); let tm: DateTime = tm.into(); tm.format(PRETTY_DATETIME_FORMAT).to_string() diff --git a/src/uu/tail/src/args.rs b/src/uu/tail/src/args.rs index 64b600f63..4136b8597 100644 --- a/src/uu/tail/src/args.rs +++ b/src/uu/tail/src/args.rs @@ -181,7 +181,7 @@ impl Settings { settings } - pub fn from(matches: &clap::ArgMatches) -> UResult { + pub fn from(matches: &ArgMatches) -> UResult { // We're parsing --follow, -F and --retry under the following conditions: // * -F sets --retry and --follow=name // * plain --follow or short -f is the same like specifying --follow=descriptor @@ -236,7 +236,7 @@ impl Settings { // * not applied here but it supports customizable time units and provides better error // messages settings.sleep_sec = match DurationParser::without_time_units().parse(source) { - Ok(duration) => SaturatingInto::::saturating_into(duration), + Ok(duration) => SaturatingInto::::saturating_into(duration), Err(_) => { return Err(UUsageError::new( 1, diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index ddd0fc696..98719ddce 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -229,7 +229,7 @@ impl Observer { watcher = Box::new(notify::PollWatcher::new(tx, watcher_config).unwrap()); } else { let tx_clone = tx.clone(); - match notify::RecommendedWatcher::new(tx, notify::Config::default()) { + match RecommendedWatcher::new(tx, notify::Config::default()) { Ok(w) => watcher = Box::new(w), Err(e) if e.to_string().starts_with("Too many open files") => { /* diff --git a/src/uu/tail/src/platform/unix.rs b/src/uu/tail/src/platform/unix.rs index a04582a2c..08e75bedf 100644 --- a/src/uu/tail/src/platform/unix.rs +++ b/src/uu/tail/src/platform/unix.rs @@ -11,11 +11,11 @@ use std::io::Error; pub type Pid = libc::pid_t; pub struct ProcessChecker { - pid: self::Pid, + pid: Pid, } impl ProcessChecker { - pub fn new(process_id: self::Pid) -> Self { + pub fn new(process_id: Pid) -> Self { Self { pid: process_id } } @@ -30,7 +30,7 @@ impl Drop for ProcessChecker { fn drop(&mut self) {} } -pub fn supports_pid_checks(pid: self::Pid) -> bool { +pub fn supports_pid_checks(pid: Pid) -> bool { unsafe { !(libc::kill(pid, 0) != 0 && get_errno() == libc::ENOSYS) } } diff --git a/src/uu/tail/src/platform/windows.rs b/src/uu/tail/src/platform/windows.rs index e3b236b12..550f76bcc 100644 --- a/src/uu/tail/src/platform/windows.rs +++ b/src/uu/tail/src/platform/windows.rs @@ -16,7 +16,7 @@ pub struct ProcessChecker { } impl ProcessChecker { - pub fn new(process_id: self::Pid) -> Self { + pub fn new(process_id: Pid) -> Self { #[allow(non_snake_case)] let FALSE: BOOL = 0; let h = unsafe { OpenProcess(PROCESS_SYNCHRONIZE, FALSE, process_id) }; @@ -47,6 +47,6 @@ impl Drop for ProcessChecker { } } -pub fn supports_pid_checks(_pid: self::Pid) -> bool { +pub fn supports_pid_checks(_pid: Pid) -> bool { true } diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index 0539ec6f3..665ee1ea9 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -163,7 +163,7 @@ fn tail_file( true, )?; } - Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => { + Err(e) if e.kind() == ErrorKind::PermissionDenied => { observer.add_bad_path(path, input.display_name.as_str(), false)?; show!(e.map_err_context(|| { format!("cannot open '{}' for reading", input.display_name) @@ -290,7 +290,7 @@ fn forwards_thru_file( reader: &mut impl Read, num_delimiters: u64, delimiter: u8, -) -> std::io::Result { +) -> io::Result { // If num_delimiters == 0, always return 0. if num_delimiters == 0 { return Ok(0); @@ -405,7 +405,7 @@ fn bounded_tail(file: &mut File, settings: &Settings) { // Print the target section of the file. let stdout = stdout(); let mut stdout = stdout.lock(); - std::io::copy(file, &mut stdout).unwrap(); + io::copy(file, &mut stdout).unwrap(); } fn unbounded_tail(reader: &mut BufReader, settings: &Settings) -> UResult<()> { diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index eaf5112ab..a6cbaec79 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -66,7 +66,7 @@ impl Config { Some(signal_value) => signal_value, } } - _ => uucore::signals::signal_by_name_or_value("TERM").unwrap(), + _ => signal_by_name_or_value("TERM").unwrap(), }; let kill_after = match options.get_one::(options::KILL_AFTER) { diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 1174fc156..82bb7e806 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -443,7 +443,7 @@ fn touch_file( }; if let Err(e) = metadata_result { - if e.kind() != std::io::ErrorKind::NotFound { + if e.kind() != ErrorKind::NotFound { return Err(e.map_err_context(|| format!("setting times of {}", filename.quote()))); } @@ -687,7 +687,7 @@ fn parse_timestamp(s: &str) -> UResult { let local = NaiveDateTime::parse_from_str(&ts, format) .map_err(|_| USimpleError::new(1, format!("invalid date ts format {}", ts.quote())))?; - let LocalResult::Single(mut local) = chrono::Local.from_local_datetime(&local) else { + let LocalResult::Single(mut local) = Local.from_local_datetime(&local) else { return Err(USimpleError::new( 1, format!("invalid date ts format {}", ts.quote()), diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index d43ae70ca..056163fa3 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -180,7 +180,7 @@ pub fn uu_app() -> Command { /// size of the file. fn file_truncate(filename: &str, create: bool, size: u64) -> UResult<()> { #[cfg(unix)] - if let Ok(metadata) = std::fs::metadata(filename) { + if let Ok(metadata) = metadata(filename) { if metadata.file_type().is_fifo() { return Err(USimpleError::new( 1, diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index a0d2db47c..5b66b4daa 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -311,7 +311,7 @@ fn next_char_info(uflag: bool, buf: &[u8], byte: usize) -> (CharType, usize, usi #[allow(clippy::cognitive_complexity)] fn unexpand_line( buf: &mut Vec, - output: &mut BufWriter, + output: &mut BufWriter, options: &Options, lastcol: usize, ts: &[usize], diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index b850e4656..f260341e6 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -805,7 +805,7 @@ fn files0_iter<'a>( }), ); // Loop until there is an error; yield that error and then nothing else. - std::iter::from_fn(move || { + iter::from_fn(move || { let next = i.as_mut().and_then(Iterator::next); if matches!(next, Some(Err(_)) | None) { i = None; From 76b1b6835c4920ec447e8b463e15a8f26bd5f684 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 10 Apr 2025 16:56:52 -0400 Subject: [PATCH 2/2] rm ptr::NonNull --- src/uu/chcon/src/fts.rs | 19 +++++++++---------- src/uu/du/src/du.rs | 8 ++++---- src/uu/numfmt/src/numfmt.rs | 6 +++--- src/uu/split/src/platform/windows.rs | 4 ++-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/uu/chcon/src/fts.rs b/src/uu/chcon/src/fts.rs index a737b5f26..c9a8599fa 100644 --- a/src/uu/chcon/src/fts.rs +++ b/src/uu/chcon/src/fts.rs @@ -8,7 +8,6 @@ use std::ffi::{CStr, CString, OsStr}; use std::marker::PhantomData; use std::os::raw::{c_int, c_long, c_short}; use std::path::Path; -use std::ptr::NonNull; use std::{io, iter, ptr, slice}; use crate::errors::{Error, Result}; @@ -16,9 +15,9 @@ use crate::os_str_to_c_string; #[derive(Debug)] pub(crate) struct FTS { - fts: NonNull, + fts: ptr::NonNull, - entry: Option>, + entry: Option>, _phantom_data: PhantomData, } @@ -52,7 +51,7 @@ impl FTS { // - `compar` is None. let fts = unsafe { fts_sys::fts_open(path_argv.as_ptr().cast(), options, None) }; - let fts = NonNull::new(fts) + let fts = ptr::NonNull::new(fts) .ok_or_else(|| Error::from_io("fts_open()", io::Error::last_os_error()))?; Ok(Self { @@ -71,7 +70,7 @@ impl FTS { // pointer assumed to be valid. let new_entry = unsafe { fts_sys::fts_read(self.fts.as_ptr()) }; - self.entry = NonNull::new(new_entry); + self.entry = ptr::NonNull::new(new_entry); if self.entry.is_none() { let r = io::Error::last_os_error(); if let Some(0) = r.raw_os_error() { @@ -110,14 +109,14 @@ impl Drop for FTS { #[derive(Debug)] pub(crate) struct EntryRef<'fts> { - pub(crate) pointer: NonNull, + pub(crate) pointer: ptr::NonNull, _fts: PhantomData<&'fts FTS>, _phantom_data: PhantomData, } impl<'fts> EntryRef<'fts> { - fn new(_fts: &'fts FTS, entry: NonNull) -> Self { + fn new(_fts: &'fts FTS, entry: ptr::NonNull) -> Self { Self { pointer: entry, _fts: PhantomData, @@ -161,7 +160,7 @@ impl<'fts> EntryRef<'fts> { return None; } - NonNull::new(entry.fts_path) + ptr::NonNull::new(entry.fts_path) .map(|path_ptr| { let path_size = usize::from(entry.fts_pathlen).saturating_add(1); @@ -174,7 +173,7 @@ impl<'fts> EntryRef<'fts> { } pub(crate) fn access_path(&self) -> Option<&Path> { - NonNull::new(self.as_ref().fts_accpath) + ptr::NonNull::new(self.as_ref().fts_accpath) .map(|path_ptr| { // SAFETY: `entry.fts_accpath` is a non-null pointer that is assumed to be valid. unsafe { CStr::from_ptr(path_ptr.as_ptr()) } @@ -184,7 +183,7 @@ impl<'fts> EntryRef<'fts> { } pub(crate) fn stat(&self) -> Option<&libc::stat> { - NonNull::new(self.as_ref().fts_statp).map(|stat_ptr| { + ptr::NonNull::new(self.as_ref().fts_statp).map(|stat_ptr| { // SAFETY: `entry.fts_statp` is a non-null pointer that is assumed to be valid. unsafe { stat_ptr.as_ref() } }) diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 89a0e56b5..c1838d1db 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -227,7 +227,7 @@ fn get_size_on_disk(path: &Path) -> u64 { // bind file so it stays in scope until end of function // if it goes out of scope the handle below becomes invalid - let file = match fs::File::open(path) { + let file = match File::open(path) { Ok(file) => file, Err(_) => return size_on_disk, // opening directories will fail }; @@ -240,7 +240,7 @@ fn get_size_on_disk(path: &Path) -> u64 { file.as_raw_handle() as HANDLE, FileStandardInfo, file_info_ptr as _, - std::mem::size_of::() as u32, + size_of::() as u32, ); if success != 0 { @@ -255,7 +255,7 @@ fn get_size_on_disk(path: &Path) -> u64 { fn get_file_info(path: &Path) -> Option { let mut result = None; - let file = match fs::File::open(path) { + let file = match File::open(path) { Ok(file) => file, Err(_) => return result, }; @@ -268,7 +268,7 @@ fn get_file_info(path: &Path) -> Option { file.as_raw_handle() as HANDLE, FileIdInfo, file_info_ptr as _, - std::mem::size_of::() as u32, + size_of::() as u32, ); if success != 0 { diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index ecbdc94f3..cfa7c30d8 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -234,7 +234,7 @@ fn parse_options(args: &ArgMatches) -> Result { let invalid = InvalidModes::from_str(args.get_one::(INVALID).unwrap()).unwrap(); - let zero_terminated = args.get_flag(options::ZERO_TERMINATED); + let zero_terminated = args.get_flag(ZERO_TERMINATED); Ok(NumfmtOptions { transform, @@ -387,8 +387,8 @@ pub fn uu_app() -> Command { .value_name("INVALID"), ) .arg( - Arg::new(options::ZERO_TERMINATED) - .long(options::ZERO_TERMINATED) + Arg::new(ZERO_TERMINATED) + .long(ZERO_TERMINATED) .short('z') .help("line delimiter is NUL, not newline") .action(ArgAction::SetTrue), diff --git a/src/uu/split/src/platform/windows.rs b/src/uu/split/src/platform/windows.rs index a531d6abc..077a17ccc 100644 --- a/src/uu/split/src/platform/windows.rs +++ b/src/uu/split/src/platform/windows.rs @@ -22,7 +22,7 @@ pub fn instantiate_current_writer( .write(true) .create(true) .truncate(true) - .open(std::path::Path::new(&filename)) + .open(Path::new(&filename)) .map_err(|_| { Error::new( ErrorKind::Other, @@ -33,7 +33,7 @@ pub fn instantiate_current_writer( // re-open file that we previously created to append to it std::fs::OpenOptions::new() .append(true) - .open(std::path::Path::new(&filename)) + .open(Path::new(&filename)) .map_err(|_| { Error::new( ErrorKind::Other,