diff --git a/build.rs b/build.rs index d414de092..3b6aa3878 100644 --- a/build.rs +++ b/build.rs @@ -34,7 +34,7 @@ pub fn main() { match krate.as_ref() { "default" | "macos" | "unix" | "windows" | "selinux" | "zip" => continue, // common/standard feature names "nightly" | "test_unimplemented" | "expensive_tests" | "test_risky_names" => { - continue + continue; } // crate-local custom features "uudoc" => continue, // is not a utility "test" => continue, // over-ridden with 'uu_test' to avoid collision with rust core crate 'test' diff --git a/src/bin/uudoc.rs b/src/bin/uudoc.rs index 111e7a77f..802fa12dc 100644 --- a/src/bin/uudoc.rs +++ b/src/bin/uudoc.rs @@ -23,7 +23,9 @@ fn main() -> io::Result<()> { if tldr_zip.is_none() { println!("Warning: No tldr archive found, so the documentation will not include examples."); - println!("To include examples in the documentation, download the tldr archive and put it in the docs/ folder."); + println!( + "To include examples in the documentation, download the tldr archive and put it in the docs/ folder." + ); println!(); println!(" curl https://tldr.sh/assets/tldr.zip -o docs/tldr.zip"); println!(); diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 67bd723e1..482a09bad 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -11,8 +11,8 @@ use std::io::{self, ErrorKind, Read, Seek, SeekFrom}; use std::path::{Path, PathBuf}; use uucore::display::Quotable; use uucore::encoding::{ - for_base_common::{BASE32, BASE32HEX, BASE64, BASE64URL, BASE64_NOPAD, HEXUPPER_PERMISSIVE}, - Format, Z85Wrapper, BASE2LSBF, BASE2MSBF, + BASE2LSBF, BASE2MSBF, Format, Z85Wrapper, + for_base_common::{BASE32, BASE32HEX, BASE64, BASE64_NOPAD, BASE64URL, HEXUPPER_PERMISSIVE}, }; use uucore::encoding::{EncodingWrapper, SupportsFastDecodeAndEncode}; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; @@ -291,7 +291,7 @@ pub fn get_supports_fast_decode_and_encode( } pub mod fast_encode { - use crate::base_common::{format_read_error, WRAP_DEFAULT}; + use crate::base_common::{WRAP_DEFAULT, format_read_error}; use std::{ collections::VecDeque, io::{self, ErrorKind, Read, Write}, diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index cd0379347..6f579378e 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -6,7 +6,7 @@ // spell-checker:ignore (ToDO) fullname use clap::{Arg, ArgAction, Command}; -use std::path::{is_separator, PathBuf}; +use std::path::{PathBuf, is_separator}; use uucore::display::Quotable; use uucore::error::{UResult, UUsageError}; use uucore::line_ending::LineEnding; diff --git a/src/uu/basenc/src/basenc.rs b/src/uu/basenc/src/basenc.rs index 2de1223f4..100907652 100644 --- a/src/uu/basenc/src/basenc.rs +++ b/src/uu/basenc/src/basenc.rs @@ -6,7 +6,7 @@ // spell-checker:ignore lsbf msbf use clap::{Arg, ArgAction, Command}; -use uu_base32::base_common::{self, Config, BASE_CMD_PARSE_ERROR}; +use uu_base32::base_common::{self, BASE_CMD_PARSE_ERROR, Config}; use uucore::error::UClapError; use uucore::{ encoding::Format, diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index 8e0f167e2..d4013e0c8 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore (ToDO) nonprint nonblank nonprinting ELOOP -use std::fs::{metadata, File}; +use std::fs::{File, metadata}; use std::io::{self, BufWriter, IsTerminal, Read, Write}; /// Unix domain socket support #[cfg(unix)] @@ -18,7 +18,7 @@ use std::os::unix::net::UnixStream; use clap::{Arg, ArgAction, Command}; #[cfg(unix)] -use nix::fcntl::{fcntl, FcntlArg}; +use nix::fcntl::{FcntlArg, fcntl}; use thiserror::Error; use uucore::display::Quotable; use uucore::error::UResult; @@ -83,19 +83,11 @@ struct OutputOptions { impl OutputOptions { fn tab(&self) -> &'static str { - if self.show_tabs { - "^I" - } else { - "\t" - } + if self.show_tabs { "^I" } else { "\t" } } fn end_of_line(&self) -> &'static str { - if self.show_ends { - "$\n" - } else { - "\n" - } + if self.show_ends { "$\n" } else { "\n" } } /// We can write fast if we can simply copy the contents of the file to @@ -694,7 +686,7 @@ fn write_end_of_line( #[cfg(test)] mod tests { - use std::io::{stdout, BufWriter}; + use std::io::{BufWriter, stdout}; #[test] fn test_write_nonprint_to_end_new_line() { diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index 733c2fbea..01a97ae20 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -8,7 +8,7 @@ use uucore::display::Quotable; pub use uucore::entries; use uucore::error::{FromIo, UResult, USimpleError}; -use uucore::perms::{chown_base, options, GidUidOwnerFilter, IfFrom}; +use uucore::perms::{GidUidOwnerFilter, IfFrom, chown_base, options}; use uucore::{format_usage, help_about, help_usage}; use clap::{Arg, ArgAction, ArgMatches, Command}; @@ -76,7 +76,7 @@ fn parse_gid_and_uid(matches: &ArgMatches) -> UResult { return Err(USimpleError::new( 1, format!("invalid user: '{}'", from_group), - )) + )); } } } else { diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 0d39e533e..c45950a54 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -11,12 +11,12 @@ use std::fs; use std::os::unix::fs::{MetadataExt, PermissionsExt}; use std::path::Path; use uucore::display::Quotable; -use uucore::error::{set_exit_code, ExitCode, UResult, USimpleError, UUsageError}; +use uucore::error::{ExitCode, UResult, USimpleError, UUsageError, set_exit_code}; use uucore::fs::display_permissions_unix; use uucore::libc::mode_t; #[cfg(not(windows))] use uucore::mode; -use uucore::perms::{configure_symlink_and_recursion, TraverseSymlinks}; +use uucore::perms::{TraverseSymlinks, configure_symlink_and_recursion}; use uucore::{format_usage, help_about, help_section, help_usage, show, show_error}; const ABOUT: &str = help_about!("chmod.md"); @@ -107,7 +107,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(USimpleError::new( 1, format!("cannot stat attributes of {}: {}", fref.quote(), err), - )) + )); } }, None => None, @@ -298,7 +298,7 @@ impl Chmoder { format!( "it is dangerous to operate recursively on {}\nchmod: use --no-preserve-root to override this failsafe", filename.quote() - ) + ), )); } if self.recursive { diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index a3121bc8f..4389d92f6 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -7,7 +7,7 @@ use uucore::display::Quotable; pub use uucore::entries::{self, Group, Locate, Passwd}; -use uucore::perms::{chown_base, options, GidUidOwnerFilter, IfFrom}; +use uucore::perms::{GidUidOwnerFilter, IfFrom, chown_base, options}; use uucore::{format_usage, help_about, help_usage}; use uucore::error::{FromIo, UResult, USimpleError}; diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 63748c604..9a59c32e8 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -13,9 +13,9 @@ use std::io::Error; use std::os::unix::prelude::OsStrExt; use std::path::{Path, PathBuf}; use std::process; -use uucore::entries::{grp2gid, usr2uid, Locate, Passwd}; -use uucore::error::{set_exit_code, UClapError, UResult, UUsageError}; -use uucore::fs::{canonicalize, MissingHandling, ResolveMode}; +use uucore::entries::{Locate, Passwd, grp2gid, usr2uid}; +use uucore::error::{UClapError, UResult, UUsageError, set_exit_code}; +use uucore::fs::{MissingHandling, ResolveMode, canonicalize}; use uucore::libc::{self, chroot, setgid, setgroups, setuid}; use uucore::{format_usage, help_about, help_usage, show}; @@ -224,7 +224,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } else { ChrootError::CommandFailed(command[0].to_string(), e) } - .into()) + .into()); } }; diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index a1347d6ac..3617dd6e4 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -5,17 +5,17 @@ // spell-checker:ignore (ToDO) fname, algo use clap::builder::ValueParser; -use clap::{value_parser, Arg, ArgAction, Command}; +use clap::{Arg, ArgAction, Command, value_parser}; use std::ffi::{OsStr, OsString}; use std::fs::File; -use std::io::{self, stdin, stdout, BufReader, Read, Write}; +use std::io::{self, BufReader, Read, Write, stdin, stdout}; use std::iter; use std::path::Path; use uucore::checksum::{ - calculate_blake2b_length, detect_algo, digest_reader, perform_checksum_validation, - ChecksumError, ChecksumOptions, ChecksumVerbose, ALGORITHM_OPTIONS_BLAKE2B, - ALGORITHM_OPTIONS_BSD, ALGORITHM_OPTIONS_CRC, ALGORITHM_OPTIONS_CRC32B, ALGORITHM_OPTIONS_SYSV, - SUPPORTED_ALGORITHMS, + ALGORITHM_OPTIONS_BLAKE2B, ALGORITHM_OPTIONS_BSD, ALGORITHM_OPTIONS_CRC, + ALGORITHM_OPTIONS_CRC32B, ALGORITHM_OPTIONS_SYSV, ChecksumError, ChecksumOptions, + ChecksumVerbose, SUPPORTED_ALGORITHMS, calculate_blake2b_length, detect_algo, digest_reader, + perform_checksum_validation, }; use uucore::{ encoding, diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index 2cbed71fb..f0944ff6e 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -6,8 +6,8 @@ // spell-checker:ignore (ToDO) delim mkdelim pairable use std::cmp::Ordering; -use std::fs::{metadata, File}; -use std::io::{self, stdin, BufRead, BufReader, Read, Stdin}; +use std::fs::{File, metadata}; +use std::io::{self, BufRead, BufReader, Read, Stdin, stdin}; use uucore::error::{FromIo, UResult, USimpleError}; use uucore::fs::paths_refer_to_same_file; use uucore::line_ending::LineEnding; diff --git a/src/uu/cp/src/copydir.rs b/src/uu/cp/src/copydir.rs index bd81a39f5..cafdbd010 100644 --- a/src/uu/cp/src/copydir.rs +++ b/src/uu/cp/src/copydir.rs @@ -18,7 +18,7 @@ use indicatif::ProgressBar; use uucore::display::Quotable; use uucore::error::UIoError; use uucore::fs::{ - canonicalize, path_ends_with_terminator, FileInformation, MissingHandling, ResolveMode, + FileInformation, MissingHandling, ResolveMode, canonicalize, path_ends_with_terminator, }; use uucore::show; use uucore::show_error; @@ -26,8 +26,8 @@ use uucore::uio_error; use walkdir::{DirEntry, WalkDir}; use crate::{ - aligned_ancestors, context_for, copy_attributes, copy_file, copy_link, CopyResult, Error, - Options, + CopyResult, Error, Options, aligned_ancestors, context_for, copy_attributes, copy_file, + copy_link, }; /// Ensure a Windows path starts with a `\\?`. diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 0aab4b68a..356220f7d 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -20,7 +20,7 @@ use std::path::{Path, PathBuf, StripPrefixError}; #[cfg(all(unix, not(target_os = "android")))] use uucore::fsxattr::copy_xattrs; -use clap::{builder::ValueParser, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser}; use filetime::FileTime; use indicatif::{ProgressBar, ProgressStyle}; #[cfg(unix)] @@ -29,11 +29,11 @@ use quick_error::ResultExt; use platform::copy_on_write; use uucore::display::Quotable; -use uucore::error::{set_exit_code, UClapError, UError, UResult, UUsageError}; +use uucore::error::{UClapError, UError, UResult, UUsageError, set_exit_code}; use uucore::fs::{ - are_hardlinks_to_same_file, canonicalize, get_filename, is_symlink_loop, normalize_path, - path_ends_with_terminator, paths_refer_to_same_file, FileInformation, MissingHandling, - ResolveMode, + FileInformation, MissingHandling, ResolveMode, are_hardlinks_to_same_file, canonicalize, + get_filename, is_symlink_loop, normalize_path, path_ends_with_terminator, + paths_refer_to_same_file, }; use uucore::{backup_control, update_control}; // These are exposed for projects (e.g. nushell) that want to create an `Options` value, which @@ -1498,7 +1498,7 @@ fn file_mode_for_interactive_overwrite( { #[cfg(unix)] { - use libc::{mode_t, S_IWUSR}; + use libc::{S_IWUSR, mode_t}; use std::os::unix::prelude::MetadataExt; match path.metadata() { @@ -1631,9 +1631,9 @@ pub(crate) fn copy_attributes( #[cfg(unix)] handle_preserve(&attributes.ownership, || -> CopyResult<()> { use std::os::unix::prelude::MetadataExt; - use uucore::perms::wrap_chown; use uucore::perms::Verbosity; use uucore::perms::VerbosityLevel; + use uucore::perms::wrap_chown; let dest_uid = source_metadata.uid(); let dest_gid = source_metadata.gid(); @@ -2627,7 +2627,7 @@ fn disk_usage_directory(p: &Path) -> io::Result { #[cfg(test)] mod tests { - use crate::{aligned_ancestors, localize_to_target, Attributes, Preserve}; + use crate::{Attributes, Preserve, aligned_ancestors, localize_to_target}; use std::path::Path; #[test] diff --git a/src/uu/cp/src/platform/linux.rs b/src/uu/cp/src/platform/linux.rs index 4da76522f..9bf257f82 100644 --- a/src/uu/cp/src/platform/linux.rs +++ b/src/uu/cp/src/platform/linux.rs @@ -340,7 +340,7 @@ pub(crate) fn copy_on_write( } (ReflinkMode::Auto, SparseMode::Always) => { copy_debug.sparse_detection = SparseDebug::Zeros; // Default SparseDebug val for - // SparseMode::Always + // SparseMode::Always if source_is_stream { copy_debug.offload = OffloadReflinkDebug::Avoided; copy_stream(source, dest, source_is_fifo).map(|_| ()) @@ -401,7 +401,7 @@ pub(crate) fn copy_on_write( clone(source, dest, CloneFallback::Error) } (ReflinkMode::Always, _) => { - return Err("`--reflink=always` can be used only with --sparse=auto".into()) + return Err("`--reflink=always` can be used only with --sparse=auto".into()); } }; result.context(context)?; @@ -524,7 +524,7 @@ fn handle_reflink_auto_sparse_auto( } else { copy_method = CopyMethod::SparseCopyWithoutHole; } // Since sparse_flag is true, sparse_detection shall be SeekHole for any non virtual - // regular sparse file and the file will be sparsely copied + // regular sparse file and the file will be sparsely copied copy_debug.sparse_detection = SparseDebug::SeekHole; } @@ -557,7 +557,7 @@ fn handle_reflink_never_sparse_auto( if sparse_flag { if blocks == 0 && data_flag { copy_method = CopyMethod::FSCopy; // Handles virtual files which have size > 0 but no - // disk allocation + // disk allocation } else { copy_method = CopyMethod::SparseCopyWithoutHole; // Handles regular sparse-files } diff --git a/src/uu/cp/src/platform/macos.rs b/src/uu/cp/src/platform/macos.rs index 988dc6b25..ee5ddca54 100644 --- a/src/uu/cp/src/platform/macos.rs +++ b/src/uu/cp/src/platform/macos.rs @@ -84,7 +84,7 @@ pub(crate) fn copy_on_write( // support COW). match reflink_mode { ReflinkMode::Always => { - return Err(format!("failed to clone {source:?} from {dest:?}: {error}").into()) + return Err(format!("failed to clone {source:?} from {dest:?}: {error}").into()); } _ => { copy_debug.reflink = OffloadReflinkDebug::Yes; diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index e9389f9b7..4b33a45a7 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -8,7 +8,7 @@ use std::cmp::Ordering; use std::io::{self, BufReader}; use std::{ - fs::{remove_file, File}, + fs::{File, remove_file}, io::{BufRead, BufWriter, Write}, }; diff --git a/src/uu/csplit/src/split_name.rs b/src/uu/csplit/src/split_name.rs index a4bd968e5..b60d380fe 100644 --- a/src/uu/csplit/src/split_name.rs +++ b/src/uu/csplit/src/split_name.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore (regex) diuox -use uucore::format::{num_format::UnsignedInt, Format, FormatError}; +use uucore::format::{Format, FormatError, num_format::UnsignedInt}; use crate::csplit_error::CsplitError; diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index f3f268d37..0063744f8 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -6,13 +6,13 @@ // spell-checker:ignore (ToDO) delim sourcefiles use bstr::io::BufReadExt; -use clap::{builder::ValueParser, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser}; use std::ffi::OsString; use std::fs::File; -use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, IsTerminal, Read, Write}; +use std::io::{BufRead, BufReader, BufWriter, IsTerminal, Read, Write, stdin, stdout}; use std::path::Path; use uucore::display::Quotable; -use uucore::error::{set_exit_code, FromIo, UResult, USimpleError}; +use uucore::error::{FromIo, UResult, USimpleError, set_exit_code}; use uucore::line_ending::LineEnding; use uucore::os_str_as_bytes; @@ -370,16 +370,18 @@ fn cut_files(mut filenames: Vec, mode: &Mode) { continue; } - show_if_err!(File::open(path) - .map_err_context(|| filename.maybe_quote().to_string()) - .and_then(|file| { - match &mode { - Mode::Bytes(ranges, opts) | Mode::Characters(ranges, opts) => { - cut_bytes(file, ranges, opts) + show_if_err!( + File::open(path) + .map_err_context(|| filename.maybe_quote().to_string()) + .and_then(|file| { + match &mode { + Mode::Bytes(ranges, opts) | Mode::Characters(ranges, opts) => { + cut_bytes(file, ranges, opts) + } + Mode::Fields(ranges, opts) => cut_fields(file, ranges, opts), } - Mode::Fields(ranges, opts) => cut_fields(file, ranges, opts), - } - })); + }) + ); } } } diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index c0b982792..41f5b5951 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -11,7 +11,7 @@ use chrono::{DateTime, FixedOffset, Local, Offset, TimeDelta, Utc}; use chrono::{Datelike, Timelike}; use clap::{Arg, ArgAction, Command}; #[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] -use libc::{clock_settime, timespec, CLOCK_REALTIME}; +use libc::{CLOCK_REALTIME, clock_settime, timespec}; use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::PathBuf; diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 0bc13143a..84bc4a2ee 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -22,7 +22,7 @@ use nix::fcntl::FcntlArg::F_SETFL; use nix::fcntl::OFlag; use parseargs::Parser; use progress::ProgUpdateType; -use progress::{gen_prog_updater, ProgUpdate, ReadStat, StatusLevel, WriteStat}; +use progress::{ProgUpdate, ReadStat, StatusLevel, WriteStat, gen_prog_updater}; use uucore::io::OwnedFileDescriptorOrHandle; use std::cmp; @@ -41,7 +41,7 @@ use std::os::unix::{ use std::os::windows::{fs::MetadataExt, io::AsHandle}; use std::path::Path; use std::sync::atomic::AtomicU8; -use std::sync::{atomic::Ordering::Relaxed, mpsc, Arc}; +use std::sync::{Arc, atomic::Ordering::Relaxed, mpsc}; use std::thread; use std::time::{Duration, Instant}; @@ -50,12 +50,12 @@ use gcd::Gcd; #[cfg(target_os = "linux")] use nix::{ errno::Errno, - fcntl::{posix_fadvise, PosixFadviseAdvice}, + fcntl::{PosixFadviseAdvice, posix_fadvise}, }; use uucore::display::Quotable; -#[cfg(unix)] -use uucore::error::{set_exit_code, USimpleError}; use uucore::error::{FromIo, UResult}; +#[cfg(unix)] +use uucore::error::{USimpleError, set_exit_code}; #[cfg(target_os = "linux")] use uucore::show_if_err; use uucore::{format_usage, help_about, help_section, help_usage, show_error}; @@ -417,11 +417,7 @@ fn make_linux_iflags(iflags: &IFlags) -> Option { flag |= libc::O_SYNC; } - if flag == 0 { - None - } else { - Some(flag) - } + if flag == 0 { None } else { Some(flag) } } impl Read for Input<'_> { @@ -832,10 +828,9 @@ impl<'a> Output<'a> { fn discard_cache(&self, offset: libc::off_t, len: libc::off_t) { #[cfg(target_os = "linux")] { - show_if_err!(self - .dst - .discard_cache(offset, len) - .map_err_context(|| "failed to discard cache for: 'standard output'".to_string())); + show_if_err!(self.dst.discard_cache(offset, len).map_err_context(|| { + "failed to discard cache for: 'standard output'".to_string() + })); } #[cfg(target_os = "linux")] { @@ -1241,11 +1236,7 @@ fn make_linux_oflags(oflags: &OFlags) -> Option { flag |= libc::O_SYNC; } - if flag == 0 { - None - } else { - Some(flag) - } + if flag == 0 { None } else { Some(flag) } } /// Read from an input (that is, a source of bytes) into the given buffer. @@ -1441,7 +1432,7 @@ pub fn uu_app() -> Command { #[cfg(test)] mod tests { - use crate::{calc_bsize, Output, Parser}; + use crate::{Output, Parser, calc_bsize}; use std::path::Path; diff --git a/src/uu/dd/src/numbers.rs b/src/uu/dd/src/numbers.rs index d0ee2d90b..c8540e35c 100644 --- a/src/uu/dd/src/numbers.rs +++ b/src/uu/dd/src/numbers.rs @@ -90,7 +90,7 @@ pub(crate) fn to_magnitude_and_suffix(n: u128, suffix_type: SuffixType) -> Strin #[cfg(test)] mod tests { - use crate::numbers::{to_magnitude_and_suffix, SuffixType}; + use crate::numbers::{SuffixType, to_magnitude_and_suffix}; #[test] fn test_to_magnitude_and_suffix_powers_of_1024() { diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index e26b34953..fa441d12f 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -630,8 +630,8 @@ fn conversion_mode( #[cfg(test)] mod tests { - use crate::parseargs::{parse_bytes_with_opt_multiplier, Parser}; use crate::Num; + use crate::parseargs::{Parser, parse_bytes_with_opt_multiplier}; use std::matches; const BIG: &str = "9999999999999999999999999999999999999999999999999999999999999"; diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index baeafdd56..93ea76f32 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -6,11 +6,11 @@ use super::*; +use crate::StatusLevel; use crate::conversion_tables::{ ASCII_TO_EBCDIC_UCASE_TO_LCASE, ASCII_TO_IBM, EBCDIC_TO_ASCII_LCASE_TO_UCASE, }; use crate::parseargs::Parser; -use crate::StatusLevel; #[cfg(not(any(target_os = "linux", target_os = "android")))] #[allow(clippy::useless_vec)] @@ -341,7 +341,9 @@ fn parse_icf_tokens_elu() { #[test] fn parse_icf_tokens_remaining() { - let args = &["conv=ascii,ucase,block,sparse,swab,sync,noerror,excl,nocreat,notrunc,noerror,fdatasync,fsync"]; + let args = &[ + "conv=ascii,ucase,block,sparse,swab,sync,noerror,excl,nocreat,notrunc,noerror,fdatasync,fsync", + ]; assert_eq!( Parser::new().read(args), Ok(Parser { diff --git a/src/uu/dd/src/progress.rs b/src/uu/dd/src/progress.rs index 7d7554420..85f5fa85a 100644 --- a/src/uu/dd/src/progress.rs +++ b/src/uu/dd/src/progress.rs @@ -22,7 +22,7 @@ use uucore::{ format::num_format::{FloatVariant, Formatter}, }; -use crate::numbers::{to_magnitude_and_suffix, SuffixType}; +use crate::numbers::{SuffixType, to_magnitude_and_suffix}; #[derive(PartialEq, Eq)] pub(crate) enum ProgUpdateType { diff --git a/src/uu/df/src/blocks.rs b/src/uu/df/src/blocks.rs index d7a689d8c..fd955d324 100644 --- a/src/uu/df/src/blocks.rs +++ b/src/uu/df/src/blocks.rs @@ -9,7 +9,7 @@ use std::{env, fmt}; use uucore::{ display::Quotable, - parse_size::{parse_size_u64, ParseSizeError}, + parse_size::{ParseSizeError, parse_size_u64}, }; /// The first ten powers of 1024. @@ -216,7 +216,7 @@ mod tests { use std::env; - use crate::blocks::{to_magnitude_and_suffix, BlockSize, SuffixType}; + use crate::blocks::{BlockSize, SuffixType, to_magnitude_and_suffix}; #[test] fn test_to_magnitude_and_suffix_powers_of_1024() { diff --git a/src/uu/df/src/columns.rs b/src/uu/df/src/columns.rs index 3c0a24419..0a9a20b85 100644 --- a/src/uu/df/src/columns.rs +++ b/src/uu/df/src/columns.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore itotal iused iavail ipcent pcent squashfs use crate::{OPT_INODES, OPT_OUTPUT, OPT_PRINT_TYPE}; -use clap::{parser::ValueSource, ArgMatches}; +use clap::{ArgMatches, parser::ValueSource}; /// The columns in the output table produced by `df`. /// diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 8d5b7a6c5..a73cc21ef 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -13,18 +13,18 @@ use clap::builder::ValueParser; use table::HeaderMode; use uucore::display::Quotable; use uucore::error::{UError, UResult, USimpleError}; -use uucore::fsext::{read_fs_list, MountInfo}; +use uucore::fsext::{MountInfo, read_fs_list}; use uucore::parse_size::ParseSizeError; use uucore::{format_usage, help_about, help_section, help_usage, show}; -use clap::{parser::ValueSource, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource}; use std::error::Error; use std::ffi::OsString; use std::fmt; use std::path::Path; -use crate::blocks::{read_block_size, BlockSize}; +use crate::blocks::{BlockSize, read_block_size}; use crate::columns::{Column, ColumnError}; use crate::filesystem::Filesystem; use crate::filesystem::FsError; @@ -749,7 +749,7 @@ mod tests { mod is_included { - use crate::{is_included, Options}; + use crate::{Options, is_included}; use uucore::fsext::MountInfo; /// Instantiate a [`MountInfo`] with the given fields. @@ -886,7 +886,7 @@ mod tests { mod filter_mount_list { - use crate::{filter_mount_list, Options}; + use crate::{Options, filter_mount_list}; #[test] fn test_empty() { diff --git a/src/uu/df/src/filesystem.rs b/src/uu/df/src/filesystem.rs index 401a3bec7..cd9be2d83 100644 --- a/src/uu/df/src/filesystem.rs +++ b/src/uu/df/src/filesystem.rs @@ -207,7 +207,7 @@ mod tests { use uucore::fsext::MountInfo; - use crate::filesystem::{mount_info_from_path, FsError}; + use crate::filesystem::{FsError, mount_info_from_path}; // Create a fake `MountInfo` with the given directory name. fn mount_info(mount_dir: &str) -> MountInfo { @@ -312,7 +312,7 @@ mod tests { #[cfg(not(windows))] mod over_mount { - use crate::filesystem::{is_over_mounted, Filesystem, FsError}; + use crate::filesystem::{Filesystem, FsError, is_over_mounted}; use uucore::fsext::MountInfo; fn mount_info_with_dev_name(mount_dir: &str, dev_name: Option<&str>) -> MountInfo { diff --git a/src/uu/df/src/table.rs b/src/uu/df/src/table.rs index 460bd0329..be7eb8557 100644 --- a/src/uu/df/src/table.rs +++ b/src/uu/df/src/table.rs @@ -9,7 +9,7 @@ //! collection of data rows ([`Row`]), one per filesystem. use unicode_width::UnicodeWidthStr; -use crate::blocks::{to_magnitude_and_suffix, SuffixType}; +use crate::blocks::{SuffixType, to_magnitude_and_suffix}; use crate::columns::{Alignment, Column}; use crate::filesystem::Filesystem; use crate::{BlockSize, Options}; diff --git a/src/uu/dir/src/dir.rs b/src/uu/dir/src/dir.rs index e25529511..0a8a71c22 100644 --- a/src/uu/dir/src/dir.rs +++ b/src/uu/dir/src/dir.rs @@ -6,7 +6,7 @@ use clap::Command; use std::ffi::OsString; use std::path::Path; -use uu_ls::{options, Config, Format}; +use uu_ls::{Config, Format, options}; use uucore::error::UResult; use uucore::quoting_style::{Quotes, QuotingStyle}; diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 4b642947f..d87383db2 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use chrono::{DateTime, Local}; -use clap::{builder::PossibleValue, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, builder::PossibleValue}; use glob::Pattern; use std::collections::HashSet; use std::env; @@ -24,19 +24,19 @@ use std::sync::mpsc; use std::thread; use std::time::{Duration, UNIX_EPOCH}; use thiserror::Error; -use uucore::display::{print_verbatim, Quotable}; -use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError}; +use uucore::display::{Quotable, print_verbatim}; +use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code}; use uucore::line_ending::LineEnding; use uucore::parse_glob; -use uucore::parse_size::{parse_size_u64, ParseSizeError}; +use uucore::parse_size::{ParseSizeError, parse_size_u64}; use uucore::shortcut_value_parser::ShortcutValueParser; use uucore::{format_usage, help_about, help_section, help_usage, show, show_error, show_warning}; #[cfg(windows)] use windows_sys::Win32::Foundation::HANDLE; #[cfg(windows)] use windows_sys::Win32::Storage::FileSystem::{ - FileIdInfo, FileStandardInfo, GetFileInformationByHandleEx, FILE_ID_128, FILE_ID_INFO, - FILE_STANDARD_INFO, + FILE_ID_128, FILE_ID_INFO, FILE_STANDARD_INFO, FileIdInfo, FileStandardInfo, + GetFileInformationByHandleEx, }; mod options { @@ -593,7 +593,7 @@ fn read_files_from(file_name: &str) -> Result, std::io::Error> { return Err(std::io::Error::new( std::io::ErrorKind::Other, format!("cannot open '{file_name}' for reading: No such file or directory"), - )) + )); } Err(e) => return Err(e), } diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index 843b30408..c8d31a729 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -9,7 +9,7 @@ use std::env; use std::ffi::{OsStr, OsString}; use std::io::{self, StdoutLock, Write}; use uucore::error::{UResult, USimpleError}; -use uucore::format::{parse_escape_only, EscapedChar, FormatChar, OctalParsing}; +use uucore::format::{EscapedChar, FormatChar, OctalParsing, parse_escape_only}; use uucore::{format_usage, help_about, help_section, help_usage}; const ABOUT: &str = help_about!("echo.md"); diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index ec9360ad4..0f46b1500 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -13,14 +13,14 @@ pub mod string_parser; pub mod variable_parser; use clap::builder::ValueParser; -use clap::{crate_name, Arg, ArgAction, Command}; +use clap::{Arg, ArgAction, Command, crate_name}; use ini::Ini; use native_int_str::{ - from_native_int_representation_owned, Convert, NCvt, NativeIntStr, NativeIntString, NativeStr, + Convert, NCvt, NativeIntStr, NativeIntString, NativeStr, from_native_int_representation_owned, }; #[cfg(unix)] use nix::sys::signal::{ - raise, sigaction, signal, SaFlags, SigAction, SigHandler, SigHandler::SigIgn, SigSet, Signal, + SaFlags, SigAction, SigHandler, SigHandler::SigIgn, SigSet, Signal, raise, sigaction, signal, }; use std::borrow::Cow; use std::env; diff --git a/src/uu/env/src/native_int_str.rs b/src/uu/env/src/native_int_str.rs index dc1e741e1..06252b325 100644 --- a/src/uu/env/src/native_int_str.rs +++ b/src/uu/env/src/native_int_str.rs @@ -19,10 +19,10 @@ use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::os::windows::prelude::*; use std::{borrow::Cow, ffi::OsStr}; -#[cfg(target_os = "windows")] -use u16 as NativeIntCharU; #[cfg(not(target_os = "windows"))] use u8 as NativeIntCharU; +#[cfg(target_os = "windows")] +use u16 as NativeIntCharU; pub type NativeCharInt = NativeIntCharU; pub type NativeIntStr = [NativeCharInt]; @@ -178,22 +178,14 @@ pub fn get_single_native_int_value(c: &char) -> Option { { let mut buf = [0u16, 0]; let s = c.encode_utf16(&mut buf); - if s.len() == 1 { - Some(buf[0]) - } else { - None - } + if s.len() == 1 { Some(buf[0]) } else { None } } #[cfg(not(target_os = "windows"))] { let mut buf = [0u8, 0, 0, 0]; let s = c.encode_utf8(&mut buf); - if s.len() == 1 { - Some(buf[0]) - } else { - None - } + if s.len() == 1 { Some(buf[0]) } else { None } } } diff --git a/src/uu/env/src/split_iterator.rs b/src/uu/env/src/split_iterator.rs index 77078bd5e..379ec3bb7 100644 --- a/src/uu/env/src/split_iterator.rs +++ b/src/uu/env/src/split_iterator.rs @@ -20,10 +20,10 @@ use std::borrow::Cow; -use crate::native_int_str::from_native_int_representation; use crate::native_int_str::NativeCharInt; use crate::native_int_str::NativeIntStr; use crate::native_int_str::NativeIntString; +use crate::native_int_str::from_native_int_representation; use crate::parse_error::ParseError; use crate::string_expander::StringExpander; use crate::string_parser::StringParser; @@ -256,7 +256,7 @@ impl<'a> SplitIterator<'a> { return Err(ParseError::MissingClosingQuote { pos: self.get_parser().get_peek_position(), c: '\'', - }) + }); } Some(SINGLE_QUOTES) => { self.skip_one()?; @@ -306,7 +306,7 @@ impl<'a> SplitIterator<'a> { return Err(ParseError::MissingClosingQuote { pos: self.get_parser().get_peek_position(), c: '"', - }) + }); } Some(DOLLAR) => { self.substitute_variable()?; diff --git a/src/uu/env/src/string_expander.rs b/src/uu/env/src/string_expander.rs index 06e469926..c733523e5 100644 --- a/src/uu/env/src/string_expander.rs +++ b/src/uu/env/src/string_expander.rs @@ -10,7 +10,7 @@ use std::{ }; use crate::{ - native_int_str::{to_native_int_representation, NativeCharInt, NativeIntStr}, + native_int_str::{NativeCharInt, NativeIntStr, to_native_int_representation}, string_parser::{Chunk, Error, StringParser}, }; diff --git a/src/uu/env/src/string_parser.rs b/src/uu/env/src/string_parser.rs index 5cc8d77a1..84eb346fa 100644 --- a/src/uu/env/src/string_parser.rs +++ b/src/uu/env/src/string_parser.rs @@ -9,8 +9,8 @@ use std::{borrow::Cow, ffi::OsStr}; use crate::native_int_str::{ - from_native_int_representation, get_char_from_native_int, get_single_native_int_value, - NativeCharInt, NativeIntStr, + NativeCharInt, NativeIntStr, from_native_int_representation, get_char_from_native_int, + get_single_native_int_value, }; #[derive(Clone, Debug, Eq, PartialEq)] diff --git a/src/uu/env/src/variable_parser.rs b/src/uu/env/src/variable_parser.rs index d08c9f0dc..bd7a9c265 100644 --- a/src/uu/env/src/variable_parser.rs +++ b/src/uu/env/src/variable_parser.rs @@ -21,7 +21,10 @@ impl<'a> VariableParser<'a, '_> { if c.is_ascii_digit() { return Err(ParseError::ParsingOfVariableNameFailed { pos: self.parser.get_peek_position(), - msg: format!("Unexpected character: '{c}', expected variable name must not start with 0..9") }); + msg: format!( + "Unexpected character: '{c}', expected variable name must not start with 0..9" + ), + }); } } Ok(()) @@ -44,8 +47,10 @@ impl<'a> VariableParser<'a, '_> { match self.get_current_char() { None => { return Err(ParseError::ParsingOfVariableNameFailed { - pos: self.parser.get_peek_position(), msg: "Missing closing brace".into() }) - }, + pos: self.parser.get_peek_position(), + msg: "Missing closing brace".into(), + }); + } Some(c) if !c.is_ascii() || c.is_ascii_alphanumeric() || c == '_' => { self.skip_one()?; } @@ -56,32 +61,35 @@ impl<'a> VariableParser<'a, '_> { None => { return Err(ParseError::ParsingOfVariableNameFailed { pos: self.parser.get_peek_position(), - msg: "Missing closing brace after default value".into() }) - }, + msg: "Missing closing brace after default value".into(), + }); + } Some('}') => { default_end = Some(self.parser.get_peek_position()); self.skip_one()?; - break - }, + break; + } Some(_) => { self.skip_one()?; - }, + } } } break; - }, + } Some('}') => { varname_end = self.parser.get_peek_position(); default_end = None; self.skip_one()?; break; - }, + } Some(c) => { return Err(ParseError::ParsingOfVariableNameFailed { pos: self.parser.get_peek_position(), - msg: format!("Unexpected character: '{c}', expected a closing brace ('}}') or colon (':')") - }) - }, + msg: format!( + "Unexpected character: '{c}', expected a closing brace ('}}') or colon (':')" + ), + }); + } }; } @@ -144,7 +152,7 @@ impl<'a> VariableParser<'a, '_> { return Err(ParseError::ParsingOfVariableNameFailed { pos: self.parser.get_peek_position(), msg: "missing variable name".into(), - }) + }); } Some('{') => { self.skip_one()?; diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 34c4cda87..3cde28ac6 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -10,13 +10,13 @@ use std::error::Error; use std::ffi::OsString; use std::fmt; use std::fs::File; -use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; +use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout}; use std::num::IntErrorKind; use std::path::Path; use std::str::from_utf8; use unicode_width::UnicodeWidthChar; use uucore::display::Quotable; -use uucore::error::{set_exit_code, FromIo, UError, UResult}; +use uucore::error::{FromIo, UError, UResult, set_exit_code}; use uucore::{format_usage, help_about, help_usage, show_error}; const ABOUT: &str = help_about!("expand.md"); @@ -496,8 +496,8 @@ fn expand(options: &Options) -> UResult<()> { mod tests { use crate::is_digit_or_comma; - use super::next_tabstop; use super::RemainingMode; + use super::next_tabstop; #[test] fn test_next_tabstop_remaining_mode_none() { diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index 5c748c3e7..646deaa31 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use clap::{Arg, ArgAction, Command}; -use syntax_tree::{is_truthy, AstNode}; +use syntax_tree::{AstNode, is_truthy}; use thiserror::Error; use uucore::{ display::Quotable, diff --git a/src/uu/expr/src/syntax_tree.rs b/src/uu/expr/src/syntax_tree.rs index 45d44323c..875ebc6d6 100644 --- a/src/uu/expr/src/syntax_tree.rs +++ b/src/uu/expr/src/syntax_tree.rs @@ -87,11 +87,7 @@ impl RelationOp { Self::Geq => a >= b, } }; - if b { - Ok(1.into()) - } else { - Ok(0.into()) - } + if b { Ok(1.into()) } else { Ok(0.into()) } } } @@ -697,8 +693,8 @@ mod test { use crate::ExprError::InvalidBracketContent; use super::{ - check_posix_regex_errors, get_next_id, AstNode, AstNodeInner, BinOp, NumericOp, RelationOp, - StringOp, + AstNode, AstNodeInner, BinOp, NumericOp, RelationOp, StringOp, check_posix_regex_errors, + get_next_id, }; impl PartialEq for AstNode { diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index eda87a5b1..0627c7ee7 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -7,13 +7,13 @@ use std::collections::BTreeMap; use std::io::BufRead; -use std::io::{self, stdin, stdout, Write}; +use std::io::{self, Write, stdin, stdout}; use clap::{Arg, ArgAction, Command}; use num_bigint::BigUint; use num_traits::FromPrimitive; use uucore::display::Quotable; -use uucore::error::{set_exit_code, FromIo, UResult, USimpleError}; +use uucore::error::{FromIo, UResult, USimpleError, set_exit_code}; use uucore::{format_usage, help_about, help_usage, show_error, show_warning}; const ABOUT: &str = help_about!("factor.md"); diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 77831d3cb..fddbf3b1c 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use clap::{Arg, ArgAction, Command}; use std::{ffi::OsString, io::Write}; -use uucore::error::{set_exit_code, UResult}; +use uucore::error::{UResult, set_exit_code}; use uucore::help_about; const ABOUT: &str = help_about!("false.md"); diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index d2bf76f89..5b95219ac 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -7,7 +7,7 @@ use clap::{Arg, ArgAction, ArgMatches, Command}; use std::fs::File; -use std::io::{stdin, stdout, BufReader, BufWriter, Read, Stdout, Write}; +use std::io::{BufReader, BufWriter, Read, Stdout, Write, stdin, stdout}; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::{format_usage, help_about, help_usage}; @@ -124,7 +124,10 @@ impl FmtOptions { } (None, None) => (DEFAULT_WIDTH, DEFAULT_GOAL), }; - debug_assert!(width >= goal, "GOAL {goal} should not be greater than WIDTH {width} when given {width_opt:?} and {goal_opt:?}."); + debug_assert!( + width >= goal, + "GOAL {goal} should not be greater than WIDTH {width} when given {width_opt:?} and {goal_opt:?}." + ); if width > MAX_WIDTH { return Err(USimpleError::new( diff --git a/src/uu/fmt/src/linebreak.rs b/src/uu/fmt/src/linebreak.rs index 05d01d1a3..72f954914 100644 --- a/src/uu/fmt/src/linebreak.rs +++ b/src/uu/fmt/src/linebreak.rs @@ -8,8 +8,8 @@ use std::io::{BufWriter, Stdout, Write}; use std::{cmp, mem}; -use crate::parasplit::{ParaWords, Paragraph, WordInfo}; use crate::FmtOptions; +use crate::parasplit::{ParaWords, Paragraph, WordInfo}; struct BreakArgs<'a> { opts: &'a FmtOptions, @@ -465,11 +465,7 @@ fn restart_active_breaks<'a>( // Number of spaces to add before a word, based on mode, newline, sentence start. fn compute_slen(uniform: bool, newline: bool, start: bool, punct: bool) -> usize { if uniform || newline { - if start || (newline && punct) { - 2 - } else { - 1 - } + if start || (newline && punct) { 2 } else { 1 } } else { 0 } diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index f8ef25344..03c00735f 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -7,7 +7,7 @@ use clap::{Arg, ArgAction, Command}; use std::fs::File; -use std::io::{stdin, BufRead, BufReader, Read}; +use std::io::{BufRead, BufReader, Read, stdin}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index 4405233d0..f490ee9e5 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -8,7 +8,7 @@ use thiserror::Error; use uucore::{ display::Quotable, - entries::{get_groups_gnu, gid2grp, Locate, Passwd}, + entries::{Locate, Passwd, get_groups_gnu, gid2grp}, error::{UError, UResult}, format_usage, help_about, help_usage, show, }; diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index ce117064d..cd8ca912d 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -5,26 +5,26 @@ // spell-checker:ignore (ToDO) algo, algoname, regexes, nread, nonames +use clap::ArgAction; use clap::builder::ValueParser; use clap::value_parser; -use clap::ArgAction; use clap::{Arg, ArgMatches, Command}; use std::ffi::{OsStr, OsString}; use std::fs::File; -use std::io::{stdin, BufReader, Read}; +use std::io::{BufReader, Read, stdin}; use std::iter; use std::num::ParseIntError; use std::path::Path; +use uucore::checksum::ChecksumError; +use uucore::checksum::ChecksumOptions; +use uucore::checksum::ChecksumVerbose; +use uucore::checksum::HashAlgorithm; use uucore::checksum::calculate_blake2b_length; use uucore::checksum::create_sha3; use uucore::checksum::detect_algo; use uucore::checksum::digest_reader; use uucore::checksum::escape_filename; use uucore::checksum::perform_checksum_validation; -use uucore::checksum::ChecksumError; -use uucore::checksum::ChecksumOptions; -use uucore::checksum::ChecksumVerbose; -use uucore::checksum::HashAlgorithm; use uucore::error::{FromIo, UResult}; use uucore::sum::{Digest, Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256}; use uucore::{format_usage, help_about, help_usage}; diff --git a/src/uu/head/src/parse.rs b/src/uu/head/src/parse.rs index de49d5545..c2729ca89 100644 --- a/src/uu/head/src/parse.rs +++ b/src/uu/head/src/parse.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use std::ffi::OsString; -use uucore::parse_size::{parse_size_u64, ParseSizeError}; +use uucore::parse_size::{ParseSizeError, parse_size_u64}; #[derive(PartialEq, Eq, Debug)] pub enum ParseError { diff --git a/src/uu/head/src/take.rs b/src/uu/head/src/take.rs index a2ae6d14d..0464a397b 100644 --- a/src/uu/head/src/take.rs +++ b/src/uu/head/src/take.rs @@ -362,7 +362,7 @@ mod tests { use std::io::{BufRead, BufReader}; use crate::take::{ - copy_all_but_n_bytes, copy_all_but_n_lines, take_lines, TakeAllBuffer, TakeAllLinesBuffer, + TakeAllBuffer, TakeAllLinesBuffer, copy_all_but_n_bytes, copy_all_but_n_lines, take_lines, }; #[test] diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index f7d95cc5c..29b2bb6ba 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -34,7 +34,7 @@ static OPT_HOST: &str = "host"; mod wsa { use std::io; - use windows_sys::Win32::Networking::WinSock::{WSACleanup, WSAStartup, WSADATA}; + use windows_sys::Win32::Networking::WinSock::{WSACleanup, WSADATA, WSAStartup}; pub(super) struct WsaHandle(()); diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 658e4fff7..8a99e9758 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -38,7 +38,7 @@ use std::ffi::CStr; use uucore::display::Quotable; use uucore::entries::{self, Group, Locate, Passwd}; use uucore::error::UResult; -use uucore::error::{set_exit_code, USimpleError}; +use uucore::error::{USimpleError, set_exit_code}; pub use uucore::libc; use uucore::libc::{getlogin, uid_t}; use uucore::line_ending::LineEnding; diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 42de1ef0c..181862684 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -9,11 +9,11 @@ mod mode; use clap::{Arg, ArgAction, ArgMatches, Command}; use file_diff::diff; -use filetime::{set_file_times, FileTime}; +use filetime::{FileTime, set_file_times}; use std::fmt::Debug; use std::fs::File; use std::fs::{self, metadata}; -use std::path::{Path, PathBuf, MAIN_SEPARATOR}; +use std::path::{MAIN_SEPARATOR, Path, PathBuf}; use std::process; use thiserror::Error; use uucore::backup_control::{self, BackupMode}; @@ -23,7 +23,7 @@ use uucore::entries::{grp2gid, usr2uid}; use uucore::error::{FromIo, UError, UResult, UUsageError}; use uucore::fs::dir_strip_dot_for_creation; use uucore::mode::get_umask; -use uucore::perms::{wrap_chown, Verbosity, VerbosityLevel}; +use uucore::perms::{Verbosity, VerbosityLevel, wrap_chown}; use uucore::process::{getegid, geteuid}; use uucore::{format_usage, help_about, help_usage, show, show_error, show_if_err}; diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index 593100b7c..7251a22bc 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -7,17 +7,17 @@ use clap::builder::ValueParser; use clap::{Arg, ArgAction, Command}; -use memchr::{memchr_iter, memmem::Finder, Memchr3}; +use memchr::{Memchr3, memchr_iter, memmem::Finder}; use std::cmp::Ordering; use std::ffi::OsString; use std::fs::File; -use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Split, Stdin, Write}; +use std::io::{BufRead, BufReader, BufWriter, Split, Stdin, Write, stdin, stdout}; use std::num::IntErrorKind; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; use thiserror::Error; use uucore::display::Quotable; -use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError}; +use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code}; use uucore::line_ending::LineEnding; use uucore::{format_usage, help_about, help_usage}; diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 502a43791..27976b29c 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -11,7 +11,7 @@ use nix::unistd::Pid; use std::io::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; -use uucore::signals::{signal_by_name_or_value, signal_name_by_value, ALL_SIGNALS}; +use uucore::signals::{ALL_SIGNALS, signal_by_name_or_value, signal_name_by_value}; use uucore::{format_usage, help_about, help_usage, show}; static ABOUT: &str = help_about!("kill.md"); @@ -239,8 +239,10 @@ fn parse_pids(pids: &[String]) -> UResult> { fn kill(sig: Option, pids: &[i32]) { for &pid in pids { if let Err(e) = signal::kill(Pid::from_raw(pid), sig) { - show!(Error::from_raw_os_error(e as i32) - .map_err_context(|| format!("sending signal to {pid} failed"))); + show!( + Error::from_raw_os_error(e as i32) + .map_err_context(|| format!("sending signal to {pid} failed")) + ); } } } diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 2529fdbf7..dcaad9099 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -23,7 +23,7 @@ use std::os::unix::fs::symlink; use std::os::windows::fs::{symlink_dir, symlink_file}; use std::path::{Path, PathBuf}; use uucore::backup_control::{self, BackupMode}; -use uucore::fs::{canonicalize, MissingHandling, ResolveMode}; +use uucore::fs::{MissingHandling, ResolveMode, canonicalize}; pub struct Settings { overwrite: OverwriteMode, diff --git a/src/uu/ls/src/colors.rs b/src/uu/ls/src/colors.rs index 2a1eb254e..cc1407390 100644 --- a/src/uu/ls/src/colors.rs +++ b/src/uu/ls/src/colors.rs @@ -2,8 +2,8 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use super::get_metadata_with_deref_opt; use super::PathData; +use super::get_metadata_with_deref_opt; use lscolors::{Indicator, LsColors, Style}; use std::ffi::OsString; use std::fs::{DirEntry, Metadata}; diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index e276eaa11..21aecfd27 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -13,7 +13,7 @@ use std::{ ffi::{OsStr, OsString}, fmt::Write as FmtWrite, fs::{self, DirEntry, FileType, Metadata, ReadDir}, - io::{stdout, BufWriter, ErrorKind, Stdout, Write}, + io::{BufWriter, ErrorKind, Stdout, Write, stdout}, path::{Path, PathBuf}, time::{SystemTime, UNIX_EPOCH}, }; @@ -28,17 +28,19 @@ use std::{collections::HashSet, io::IsTerminal}; use ansi_width::ansi_width; use chrono::{DateTime, Local, TimeDelta}; use clap::{ - builder::{NonEmptyStringValueParser, PossibleValue, ValueParser}, Arg, ArgAction, Command, + builder::{NonEmptyStringValueParser, PossibleValue, ValueParser}, }; use glob::{MatchOptions, Pattern}; use lscolors::LsColors; use term_grid::{Direction, Filling, Grid, GridOptions}; use thiserror::Error; use uucore::error::USimpleError; -use uucore::format::human::{human_readable, SizeFormat}; +use uucore::format::human::{SizeFormat, human_readable}; #[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] use uucore::fsxattr::has_acl; +#[cfg(unix)] +use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; #[cfg(any( target_os = "linux", target_os = "macos", @@ -52,14 +54,12 @@ use uucore::fsxattr::has_acl; target_os = "solaris" ))] use uucore::libc::{dev_t, major, minor}; -#[cfg(unix)] -use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; use uucore::line_ending::LineEnding; -use uucore::quoting_style::{self, escape_name, QuotingStyle}; +use uucore::quoting_style::{self, QuotingStyle, escape_name}; use uucore::{ custom_tz_fmt, display::Quotable, - error::{set_exit_code, UError, UResult}, + error::{UError, UResult, set_exit_code}, format_usage, fs::display_permissions, os_str_as_bytes_lossy, @@ -70,9 +70,9 @@ use uucore::{ use uucore::{help_about, help_section, help_usage, parse_glob, show, show_error, show_warning}; mod dired; -use dired::{is_dired_arg_present, DiredOutput}; +use dired::{DiredOutput, is_dired_arg_present}; mod colors; -use colors::{color_name, StyleManager}; +use colors::{StyleManager, color_name}; #[cfg(not(feature = "selinux"))] static CONTEXT_HELP_TEXT: &str = "print any security context of each file (not enabled)"; @@ -2187,11 +2187,7 @@ fn sort_entries(entries: &mut [PathData], config: &Config, out: &mut BufWriter SizeOrDeviceId { let len_adjusted = { let d = metadata.len() / config.file_size_block_size; let r = metadata.len() % config.file_size_block_size; - if r == 0 { - d - } else { - d + 1 - } + if r == 0 { d } else { d + 1 } }; SizeOrDeviceId::Size(display_size(len_adjusted, config)) } diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 94424768d..5886127be 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -178,7 +178,7 @@ pub fn mkdir(path: &Path, recursive: bool, mode: u32, verbose: bool) -> UResult< #[cfg(any(unix, target_os = "redox"))] fn chmod(path: &Path, mode: u32) -> UResult<()> { - use std::fs::{set_permissions, Permissions}; + use std::fs::{Permissions, set_permissions}; use std::os::unix::fs::PermissionsExt; let mode = Permissions::from_mode(mode); set_permissions(path, mode) diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 485c7e558..3fb26efd1 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -5,13 +5,13 @@ // spell-checker:ignore (ToDO) parsemode makedev sysmacros perror IFBLK IFCHR IFIFO -use clap::{value_parser, Arg, ArgMatches, Command}; -use libc::{dev_t, mode_t}; +use clap::{Arg, ArgMatches, Command, value_parser}; use libc::{S_IFBLK, S_IFCHR, S_IFIFO, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR}; +use libc::{dev_t, mode_t}; use std::ffi::CString; use uucore::display::Quotable; -use uucore::error::{set_exit_code, UResult, USimpleError, UUsageError}; +use uucore::error::{UResult, USimpleError, UUsageError, set_exit_code}; use uucore::{format_usage, help_about, help_section, help_usage}; const ABOUT: &str = help_about!("mknod.md"); diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 33094bf20..8376615fd 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -5,8 +5,8 @@ // spell-checker:ignore (paths) GPGHome findxs -use clap::{builder::ValueParser, Arg, ArgAction, ArgMatches, Command}; -use uucore::display::{println_verbatim, Quotable}; +use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser}; +use uucore::display::{Quotable, println_verbatim}; use uucore::error::{FromIo, UError, UResult, UUsageError}; use uucore::{format_usage, help_about, help_usage}; @@ -14,7 +14,7 @@ use std::env; use std::ffi::OsStr; use std::io::ErrorKind; use std::iter; -use std::path::{Path, PathBuf, MAIN_SEPARATOR}; +use std::path::{MAIN_SEPARATOR, Path, PathBuf}; #[cfg(unix)] use std::fs; diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index f23f11b69..ac5e6367b 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -5,13 +5,13 @@ use std::{ fs::File, - io::{stdin, stdout, BufReader, Read, Stdout, Write}, + io::{BufReader, Read, Stdout, Write, stdin, stdout}, panic::set_hook, path::Path, time::Duration, }; -use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, value_parser}; use crossterm::event::KeyEventKind; use crossterm::{ cursor::{MoveTo, MoveUp}, diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 7ad267cf8..d4260c074 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -8,7 +8,7 @@ mod error; use clap::builder::ValueParser; -use clap::{error::ErrorKind, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, error::ErrorKind}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use std::collections::HashSet; use std::env; @@ -19,13 +19,13 @@ use std::io; use std::os::unix; #[cfg(windows)] use std::os::windows; -use std::path::{absolute, Path, PathBuf}; +use std::path::{Path, PathBuf, absolute}; use uucore::backup_control::{self, source_is_target_backup}; use uucore::display::Quotable; -use uucore::error::{set_exit_code, FromIo, UResult, USimpleError, UUsageError}; +use uucore::error::{FromIo, UResult, USimpleError, UUsageError, set_exit_code}; use uucore::fs::{ - are_hardlinks_or_one_way_symlink_to_same_file, are_hardlinks_to_same_file, canonicalize, - path_ends_with_terminator, MissingHandling, ResolveMode, + MissingHandling, ResolveMode, are_hardlinks_or_one_way_symlink_to_same_file, + are_hardlinks_to_same_file, canonicalize, path_ends_with_terminator, }; #[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))] use uucore::fsxattr; @@ -37,8 +37,8 @@ pub use uucore::{backup_control::BackupMode, update_control::UpdateMode}; use uucore::{format_usage, help_about, help_section, help_usage, prompt_yes, show}; use fs_extra::dir::{ - get_size as dir_get_size, move_dir, move_dir_with_progress, CopyOptions as DirCopyOptions, - TransitProcess, TransitProcessResult, + CopyOptions as DirCopyOptions, TransitProcess, TransitProcessResult, get_size as dir_get_size, + move_dir, move_dir_with_progress, }; use crate::error::MvError; diff --git a/src/uu/nice/src/nice.rs b/src/uu/nice/src/nice.rs index 55930f774..843dbefbb 100644 --- a/src/uu/nice/src/nice.rs +++ b/src/uu/nice/src/nice.rs @@ -5,14 +5,14 @@ // spell-checker:ignore (ToDO) getpriority execvp setpriority nstr PRIO cstrs ENOENT -use libc::{c_char, c_int, execvp, PRIO_PROCESS}; +use libc::{PRIO_PROCESS, c_char, c_int, execvp}; use std::ffi::{CString, OsString}; use std::io::{Error, Write}; use std::ptr; use clap::{Arg, ArgAction, Command}; use uucore::{ - error::{set_exit_code, UClapError, UResult, USimpleError, UUsageError}, + error::{UClapError, UResult, USimpleError, UUsageError, set_exit_code}, format_usage, help_about, help_usage, show_error, }; @@ -132,7 +132,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(USimpleError::new( 125, format!("\"{nstr}\" is not a valid number: {e}"), - )) + )); } } } diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 3a2ba2eef..6acfccfd8 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -5,9 +5,9 @@ use clap::{Arg, ArgAction, Command}; use std::fs::File; -use std::io::{stdin, BufRead, BufReader, Read}; +use std::io::{BufRead, BufReader, Read, stdin}; use std::path::Path; -use uucore::error::{set_exit_code, FromIo, UResult, USimpleError}; +use uucore::error::{FromIo, UResult, USimpleError, set_exit_code}; use uucore::{format_usage, help_about, help_section, help_usage, show_error}; mod helper; diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 5fcaeb090..d8768ec5f 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -6,8 +6,8 @@ // spell-checker:ignore (ToDO) execvp SIGHUP cproc vprocmgr cstrs homeout use clap::{Arg, ArgAction, Command}; +use libc::{SIG_IGN, SIGHUP}; use libc::{c_char, dup2, execvp, signal}; -use libc::{SIGHUP, SIG_IGN}; use std::env; use std::ffi::CString; use std::fs::{File, OpenOptions}; @@ -16,7 +16,7 @@ use std::os::unix::prelude::*; use std::path::{Path, PathBuf}; use thiserror::Error; use uucore::display::Quotable; -use uucore::error::{set_exit_code, UClapError, UError, UResult}; +use uucore::error::{UClapError, UError, UResult, set_exit_code}; use uucore::{format_usage, help_about, help_section, help_usage, show_error}; const ABOUT: &str = help_about!("nohup.md"); diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs index 130392422..7221440cb 100644 --- a/src/uu/numfmt/src/format.rs +++ b/src/uu/numfmt/src/format.rs @@ -6,7 +6,7 @@ use uucore::display::Quotable; use crate::options::{NumfmtOptions, RoundMethod, TransformOptions}; -use crate::units::{DisplayableSuffix, RawSuffix, Result, Suffix, Unit, IEC_BASES, SI_BASES}; +use crate::units::{DisplayableSuffix, IEC_BASES, RawSuffix, Result, SI_BASES, Suffix, Unit}; /// Iterate over a line's fields, where each field is a contiguous sequence of /// non-whitespace, optionally prefixed with one or more characters of leading @@ -156,11 +156,7 @@ fn transform_from(s: &str, opts: &TransformOptions) -> Result { remove_suffix(i, suffix, &opts.from).map(|n| { // GNU numfmt doesn't round values if no --from argument is provided by the user if opts.from == Unit::None { - if n == -0.0 { - 0.0 - } else { - n - } + if n == -0.0 { 0.0 } else { n } } else if n < 0.0 { -n.abs().ceil() } else { diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 1be4e6dc7..903f39a10 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -7,7 +7,7 @@ use crate::errors::*; use crate::format::format_and_print; use crate::options::*; use crate::units::{Result, Unit}; -use clap::{parser::ValueSource, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource}; use std::io::{BufRead, Write}; use std::str::FromStr; @@ -378,8 +378,8 @@ mod tests { use uucore::error::get_exit_code; use super::{ - handle_args, handle_buffer, parse_unit_size, parse_unit_size_suffix, FormatOptions, - InvalidModes, NumfmtOptions, Range, RoundMethod, TransformOptions, Unit, + FormatOptions, InvalidModes, NumfmtOptions, Range, RoundMethod, TransformOptions, Unit, + handle_args, handle_buffer, parse_unit_size, parse_unit_size_suffix, }; use std::io::{BufReader, Error, ErrorKind, Read}; struct MockBuffer {} diff --git a/src/uu/numfmt/src/options.rs b/src/uu/numfmt/src/options.rs index 88e64e963..c61be0b70 100644 --- a/src/uu/numfmt/src/options.rs +++ b/src/uu/numfmt/src/options.rs @@ -167,7 +167,7 @@ impl FromStr for FormatOptions { _ => { return Err(format!( "invalid format '{s}', directive must be %[0]['][-][N][.][N]f" - )) + )); } } } diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 6db6f5b35..e92452d60 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -33,14 +33,14 @@ use crate::inputdecoder::{InputDecoder, MemoryDecoder}; use crate::inputoffset::{InputOffset, Radix}; use crate::multifilereader::{HasError, InputSource, MultifileReader}; use crate::output_info::OutputInfo; -use crate::parse_formats::{parse_format_flags, ParsedFormatterItemInfo}; -use crate::parse_inputs::{parse_inputs, CommandLineInputs}; +use crate::parse_formats::{ParsedFormatterItemInfo, parse_format_flags}; +use crate::parse_inputs::{CommandLineInputs, parse_inputs}; use crate::parse_nrofbytes::parse_number_of_bytes; use crate::partialreader::PartialReader; use crate::peekreader::{PeekRead, PeekReader}; use crate::prn_char::format_ascii_dump; use clap::ArgAction; -use clap::{parser::ValueSource, Arg, ArgMatches, Command}; +use clap::{Arg, ArgMatches, Command, parser::ValueSource}; use uucore::display::Quotable; use uucore::error::{UResult, USimpleError}; use uucore::parse_size::ParseSizeError; @@ -89,7 +89,7 @@ impl OdOptions { return Err(USimpleError::new( 1, format!("Invalid argument --endian={s}"), - )) + )); } } } else { @@ -104,7 +104,7 @@ impl OdOptions { return Err(USimpleError::new( 1, format_error_message(&e, s, options::SKIP_BYTES), - )) + )); } }, }; @@ -135,7 +135,7 @@ impl OdOptions { return Err(USimpleError::new( 1, format_error_message(&e, s, options::WIDTH), - )) + )); } } } else { @@ -162,7 +162,7 @@ impl OdOptions { return Err(USimpleError::new( 1, format_error_message(&e, s, options::READ_BYTES), - )) + )); } }, }; @@ -585,7 +585,7 @@ fn print_bytes(prefix: &str, input_decoder: &MemoryDecoder, output_info: &Output if first { print!("{prefix}"); // print offset - // if printing in multiple formats offset is printed only once + // if printing in multiple formats offset is printed only once first = false; } else { // this takes the space of the file offset on subsequent diff --git a/src/uu/od/src/parse_nrofbytes.rs b/src/uu/od/src/parse_nrofbytes.rs index 1aa69909f..d4aabad26 100644 --- a/src/uu/od/src/parse_nrofbytes.rs +++ b/src/uu/od/src/parse_nrofbytes.rs @@ -2,7 +2,7 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use uucore::parse_size::{parse_size_u64, ParseSizeError}; +use uucore::parse_size::{ParseSizeError, parse_size_u64}; pub fn parse_number_of_bytes(s: &str) -> Result { let mut start = 0; diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 23660e9cf..c6ba8bbf9 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -6,7 +6,7 @@ use clap::{Arg, ArgAction, Command}; use std::cell::{OnceCell, RefCell}; use std::fs::File; -use std::io::{stdin, stdout, BufRead, BufReader, Stdin, Write}; +use std::io::{BufRead, BufReader, Stdin, Write, stdin, stdout}; use std::iter::Cycle; use std::rc::Rc; use std::slice::Iter; diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 7bac587a4..b0e95b718 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -9,7 +9,7 @@ use clap::{Arg, ArgAction, Command}; use std::fs; use std::io::{ErrorKind, Write}; use uucore::display::Quotable; -use uucore::error::{set_exit_code, UResult, UUsageError}; +use uucore::error::{UResult, UUsageError, set_exit_code}; use uucore::{format_usage, help_about, help_usage}; // operating mode diff --git a/src/uu/pinky/src/platform/unix.rs b/src/uu/pinky/src/platform/unix.rs index aa6d57b3f..ff29b7a6b 100644 --- a/src/uu/pinky/src/platform/unix.rs +++ b/src/uu/pinky/src/platform/unix.rs @@ -5,17 +5,17 @@ // spell-checker:ignore (ToDO) BUFSIZE gecos fullname, mesg iobuf +use crate::Capitalize; use crate::options; use crate::uu_app; -use crate::Capitalize; use uucore::entries::{Locate, Passwd}; use uucore::error::{FromIo, UResult}; use uucore::libc::S_IWGRP; -use uucore::utmpx::{self, time, Utmpx}; +use uucore::utmpx::{self, Utmpx, time}; -use std::io::prelude::*; use std::io::BufReader; +use std::io::prelude::*; use std::fs::File; use std::os::unix::fs::MetadataExt; diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index c72eb2854..6aed38d88 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -11,8 +11,8 @@ use clap::{Arg, ArgAction, ArgMatches, Command}; use itertools::Itertools; use quick_error::ResultExt; use regex::Regex; -use std::fs::{metadata, File}; -use std::io::{stdin, stdout, BufRead, BufReader, Lines, Read, Write}; +use std::fs::{File, metadata}; +use std::io::{BufRead, BufReader, Lines, Read, Write, stdin, stdout}; #[cfg(unix)] use std::os::unix::fs::FileTypeExt; diff --git a/src/uu/printenv/src/printenv.rs b/src/uu/printenv/src/printenv.rs index 7af41b0ce..4584a09b8 100644 --- a/src/uu/printenv/src/printenv.rs +++ b/src/uu/printenv/src/printenv.rs @@ -50,11 +50,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } - if error_found { - Err(1.into()) - } else { - Ok(()) - } + if error_found { Err(1.into()) } else { Ok(()) } } pub fn uu_app() -> Command { diff --git a/src/uu/printf/src/printf.rs b/src/uu/printf/src/printf.rs index 89123c48c..49d738ac9 100644 --- a/src/uu/printf/src/printf.rs +++ b/src/uu/printf/src/printf.rs @@ -6,7 +6,7 @@ use clap::{Arg, ArgAction, Command}; use std::io::stdout; use std::ops::ControlFlow; use uucore::error::{UResult, UUsageError}; -use uucore::format::{parse_spec_and_escape, FormatArgument, FormatItem}; +use uucore::format::{FormatArgument, FormatItem, parse_spec_and_escape}; use uucore::{format_usage, help_about, help_section, help_usage, show_warning}; const VERSION: &str = "version"; diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index b833282d8..12686474e 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -12,7 +12,7 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use std::error::Error; use std::fmt::{Display, Formatter, Write as FmtWrite}; use std::fs::File; -use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; +use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout}; use std::num::ParseIntError; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, UUsageError}; diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index 1ae49c023..86eca253a 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -7,11 +7,11 @@ use clap::{Arg, ArgAction, Command}; use std::fs; -use std::io::{stdout, Write}; +use std::io::{Write, stdout}; use std::path::{Path, PathBuf}; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; -use uucore::fs::{canonicalize, MissingHandling, ResolveMode}; +use uucore::fs::{MissingHandling, ResolveMode, canonicalize}; use uucore::line_ending::LineEnding; use uucore::{format_usage, help_about, help_usage, show_error}; diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index d3017e763..94532b755 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -5,17 +5,17 @@ // spell-checker:ignore (ToDO) retcode -use clap::{builder::NonEmptyStringValueParser, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, builder::NonEmptyStringValueParser}; use std::{ - io::{stdout, Write}, + io::{Write, stdout}, path::{Path, PathBuf}, }; use uucore::fs::make_path_relative_to; use uucore::{ - display::{print_verbatim, Quotable}, + display::{Quotable, print_verbatim}, error::{FromIo, UClapError, UResult}, format_usage, - fs::{canonicalize, MissingHandling, ResolveMode}, + fs::{MissingHandling, ResolveMode, canonicalize}, help_about, help_usage, line_ending::LineEnding, show_if_err, diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 24799e469..09458d4d8 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -5,7 +5,7 @@ // spell-checker:ignore (path) eacces inacc rm-r4 -use clap::{builder::ValueParser, parser::ValueSource, Arg, ArgAction, Command}; +use clap::{Arg, ArgAction, Command, builder::ValueParser, parser::ValueSource}; use std::ffi::{OsStr, OsString}; use std::fs::{self, Metadata}; use std::ops::BitOr; @@ -133,7 +133,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(USimpleError::new( 1, format!("Invalid argument to interactive ({val})"), - )) + )); } } } else { diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index 38f70c503..c70c8685f 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -12,7 +12,7 @@ use std::fs::{read_dir, remove_dir}; use std::io; use std::path::Path; use uucore::display::Quotable; -use uucore::error::{set_exit_code, strip_errno, UResult}; +use uucore::error::{UResult, set_exit_code, strip_errno}; use uucore::{format_usage, help_about, help_usage, show_error, util_name}; diff --git a/src/uu/seq/src/hexadecimalfloat.rs b/src/uu/seq/src/hexadecimalfloat.rs index de89f172e..1624fb183 100644 --- a/src/uu/seq/src/hexadecimalfloat.rs +++ b/src/uu/seq/src/hexadecimalfloat.rs @@ -255,7 +255,7 @@ fn parse_exponent_part(s: &str) -> Result<(Option, &str), ParseNumberError> mod tests { use super::{parse_number, parse_precision}; - use crate::{numberparse::ParseNumberError, ExtendedBigDecimal}; + use crate::{ExtendedBigDecimal, numberparse::ParseNumberError}; use bigdecimal::BigDecimal; use num_traits::ToPrimitive; diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 36b0a6a9f..827a8335e 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -4,14 +4,14 @@ // file that was distributed with this source code. // spell-checker:ignore (ToDO) bigdecimal extendedbigdecimal numberparse hexadecimalfloat use std::ffi::OsString; -use std::io::{stdout, BufWriter, ErrorKind, Write}; +use std::io::{BufWriter, ErrorKind, Write, stdout}; use clap::{Arg, ArgAction, Command}; use num_traits::Zero; use uucore::error::{FromIo, UResult}; use uucore::format::num_format::FloatVariant; -use uucore::format::{num_format, ExtendedBigDecimal, Format}; +use uucore::format::{ExtendedBigDecimal, Format, num_format}; use uucore::{format_usage, help_about, help_usage}; mod error; diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index dbb005538..d45a2b7b3 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -8,7 +8,7 @@ use clap::{Arg, ArgAction, Command}; #[cfg(unix)] use libc::S_IWUSR; -use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng}; +use rand::{Rng, SeedableRng, rngs::StdRng, seq::SliceRandom}; use std::fs::{self, File, OpenOptions}; use std::io::{self, Seek, Write}; #[cfg(unix)] @@ -229,7 +229,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(USimpleError::new( 1, format!("invalid number of passes: {}", s.quote()), - )) + )); } }, None => unreachable!(), @@ -456,7 +456,7 @@ fn wipe_file( pass_sequence.shuffle(&mut rng); // randomize the order of application let n_random = 3 + n_passes / 10; // Minimum 3 random passes; ratio of 10 after - // Evenly space random passes; ensures one at the beginning and end + // Evenly space random passes; ensures one at the beginning and end for i in 0..n_random { pass_sequence[i * (n_passes - 1) / (n_random - 1)] = PassType::Random; } @@ -493,8 +493,10 @@ fn wipe_file( } // size is an optional argument for exactly how many bytes we want to shred // Ignore failed writes; just keep trying - show_if_err!(do_pass(&mut file, &pass_type, exact, size) - .map_err_context(|| format!("{}: File write pass failed", path.maybe_quote()))); + show_if_err!( + do_pass(&mut file, &pass_type, exact, size) + .map_err_context(|| format!("{}: File write pass failed", path.maybe_quote())) + ); } if remove_method != RemoveMethod::None { diff --git a/src/uu/shuf/src/rand_read_adapter.rs b/src/uu/shuf/src/rand_read_adapter.rs index 589f05106..f377225a8 100644 --- a/src/uu/shuf/src/rand_read_adapter.rs +++ b/src/uu/shuf/src/rand_read_adapter.rs @@ -16,7 +16,7 @@ use std::fmt; use std::io::Read; -use rand_core::{impls, RngCore}; +use rand_core::{RngCore, impls}; /// An RNG that reads random bytes straight from any type supporting /// [`std::io::Read`], for example files. diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index ae35469a7..404d96034 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -13,7 +13,7 @@ use rand::{Rng, RngCore}; use std::collections::HashSet; use std::ffi::{OsStr, OsString}; use std::fs::File; -use std::io::{stdin, stdout, BufWriter, Error, Read, Write}; +use std::io::{BufWriter, Error, Read, Write, stdin, stdout}; use std::ops::RangeInclusive; use std::path::{Path, PathBuf}; use std::str::FromStr; diff --git a/src/uu/sort/src/check.rs b/src/uu/sort/src/check.rs index 763b6deb7..699ecae3d 100644 --- a/src/uu/sort/src/check.rs +++ b/src/uu/sort/src/check.rs @@ -6,8 +6,9 @@ //! Check if a file is ordered use crate::{ + GlobalSettings, SortError, chunks::{self, Chunk, RecycledChunk}, - compare_by, open, GlobalSettings, SortError, + compare_by, open, }; use itertools::Itertools; use std::{ @@ -15,7 +16,7 @@ use std::{ ffi::OsStr, io::Read, iter, - sync::mpsc::{sync_channel, Receiver, SyncSender}, + sync::mpsc::{Receiver, SyncSender, sync_channel}, thread, }; use uucore::error::UResult; diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index 86b734796..6f0ba97bf 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -17,7 +17,7 @@ use memchr::memchr_iter; use self_cell::self_cell; use uucore::error::{UResult, USimpleError}; -use crate::{numeric_str_cmp::NumInfo, GeneralF64ParseResult, GlobalSettings, Line, SortError}; +use crate::{GeneralF64ParseResult, GlobalSettings, Line, SortError, numeric_str_cmp::NumInfo}; self_cell!( /// The chunk that is passed around between threads. diff --git a/src/uu/sort/src/ext_sort.rs b/src/uu/sort/src/ext_sort.rs index f984760bd..cc042a2de 100644 --- a/src/uu/sort/src/ext_sort.rs +++ b/src/uu/sort/src/ext_sort.rs @@ -22,18 +22,19 @@ use std::{ use itertools::Itertools; use uucore::error::UResult; +use crate::Output; use crate::chunks::RecycledChunk; use crate::merge::ClosedTmpFile; use crate::merge::WriteableCompressedTmpFile; use crate::merge::WriteablePlainTmpFile; use crate::merge::WriteableTmpFile; use crate::tmp_dir::TmpDirWrapper; -use crate::Output; use crate::{ + GlobalSettings, chunks::{self, Chunk}, - compare_by, merge, sort_by, GlobalSettings, + compare_by, merge, sort_by, }; -use crate::{print_sorted, Line}; +use crate::{Line, print_sorted}; const START_BUFFER_SIZE: usize = 8_000; diff --git a/src/uu/sort/src/merge.rs b/src/uu/sort/src/merge.rs index 300733d1e..822eeb1d6 100644 --- a/src/uu/sort/src/merge.rs +++ b/src/uu/sort/src/merge.rs @@ -20,7 +20,7 @@ use std::{ path::{Path, PathBuf}, process::{Child, ChildStdin, ChildStdout, Command, Stdio}, rc::Rc, - sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender}, + sync::mpsc::{Receiver, Sender, SyncSender, channel, sync_channel}, thread::{self, JoinHandle}, }; @@ -28,10 +28,10 @@ use compare::Compare; use uucore::error::UResult; use crate::{ + GlobalSettings, Output, SortError, chunks::{self, Chunk, RecycledChunk}, compare_by, open, tmp_dir::TmpDirWrapper, - GlobalSettings, Output, SortError, }; /// If the output file occurs in the input files as well, copy the contents of the output file diff --git a/src/uu/sort/src/numeric_str_cmp.rs b/src/uu/sort/src/numeric_str_cmp.rs index 86cbddc64..d3d04a348 100644 --- a/src/uu/sort/src/numeric_str_cmp.rs +++ b/src/uu/sort/src/numeric_str_cmp.rs @@ -238,14 +238,14 @@ pub fn numeric_str_cmp((a, a_info): (&str, &NumInfo), (b, b_info): (&str, &NumIn Ordering::Equal } else { Ordering::Greater - } + }; } (None, Some(c)) => { break if c == '0' && b_chars.all(|c| c == '0') { Ordering::Equal } else { Ordering::Less - } + }; } (Some(a_char), Some(b_char)) => { let ord = a_char.cmp(&b_char); diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index c1247aa00..31dc81751 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -24,16 +24,16 @@ use custom_str_cmp::custom_str_cmp; use ext_sort::ext_sort; use fnv::FnvHasher; #[cfg(target_os = "linux")] -use nix::libc::{getrlimit, rlimit, RLIMIT_NOFILE}; -use numeric_str_cmp::{human_numeric_str_cmp, numeric_str_cmp, NumInfo, NumInfoParseSettings}; -use rand::{rng, Rng}; +use nix::libc::{RLIMIT_NOFILE, getrlimit, rlimit}; +use numeric_str_cmp::{NumInfo, NumInfoParseSettings, human_numeric_str_cmp, numeric_str_cmp}; +use rand::{Rng, rng}; use rayon::prelude::*; use std::cmp::Ordering; use std::env; use std::ffi::{OsStr, OsString}; use std::fs::{File, OpenOptions}; use std::hash::{Hash, Hasher}; -use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; +use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout}; use std::num::IntErrorKind; use std::ops::Range; use std::path::Path; @@ -43,7 +43,7 @@ use thiserror::Error; use unicode_width::UnicodeWidthStr; use uucore::display::Quotable; use uucore::error::strip_errno; -use uucore::error::{set_exit_code, UError, UResult, USimpleError, UUsageError}; +use uucore::error::{UError, UResult, USimpleError, UUsageError, set_exit_code}; use uucore::line_ending::LineEnding; use uucore::parse_size::{ParseSizeError, Parser}; use uucore::shortcut_value_parser::ShortcutValueParser; @@ -668,9 +668,9 @@ fn tokenize_default(line: &str, token_buffer: &mut Vec) { /// Split between separators. These separators are not included in fields. /// The result is stored into `token_buffer`. fn tokenize_with_separator(line: &str, separator: char, token_buffer: &mut Vec) { - let separator_indices = - line.char_indices() - .filter_map(|(i, c)| if c == separator { Some(i) } else { None }); + let separator_indices = line + .char_indices() + .filter_map(|(i, c)| if c == separator { Some(i) } else { None }); let mut start = 0; for sep_idx in separator_indices { token_buffer.push(start..sep_idx); @@ -707,7 +707,7 @@ impl KeyPosition { "failed to parse field index {} {}", field.quote(), e - )) + )); } }; if field == 0 { @@ -971,7 +971,9 @@ impl FieldSelector { range } Resolution::TooLow | Resolution::EndOfChar(_) => { - unreachable!("This should only happen if the field start index is 0, but that should already have caused an error.") + unreachable!( + "This should only happen if the field start index is 0, but that should already have caused an error." + ) } // While for comparisons it's only important that this is an empty slice, // to produce accurate debug output we need to match an empty slice at the end of the line. diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 34de48e15..b453040fb 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -12,13 +12,13 @@ mod strategy; use crate::filenames::{FilenameIterator, Suffix, SuffixError}; use crate::strategy::{NumberType, Strategy, StrategyError}; -use clap::{parser::ValueSource, Arg, ArgAction, ArgMatches, Command, ValueHint}; +use clap::{Arg, ArgAction, ArgMatches, Command, ValueHint, parser::ValueSource}; use std::env; use std::ffi::OsString; use std::fmt; -use std::fs::{metadata, File}; +use std::fs::{File, metadata}; use std::io; -use std::io::{stdin, BufRead, BufReader, BufWriter, ErrorKind, Read, Seek, SeekFrom, Write}; +use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Read, Seek, SeekFrom, Write, stdin}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError}; @@ -1041,7 +1041,9 @@ impl ManageOutFiles for OutFiles { } // If this fails - give up and propagate the error - uucore::show_error!("at file descriptor limit, but no file descriptor left to close. Closed {count} writers before."); + uucore::show_error!( + "at file descriptor limit, but no file descriptor left to close. Closed {count} writers before." + ); return Err(maybe_writer.err().unwrap().into()); } } diff --git a/src/uu/split/src/strategy.rs b/src/uu/split/src/strategy.rs index 7b934f720..f8f50b094 100644 --- a/src/uu/split/src/strategy.rs +++ b/src/uu/split/src/strategy.rs @@ -5,12 +5,12 @@ //! Determine the strategy for breaking up the input (file or stdin) into chunks //! based on the command line options -use crate::{OPT_BYTES, OPT_LINES, OPT_LINE_BYTES, OPT_NUMBER}; -use clap::{parser::ValueSource, ArgMatches}; +use crate::{OPT_BYTES, OPT_LINE_BYTES, OPT_LINES, OPT_NUMBER}; +use clap::{ArgMatches, parser::ValueSource}; use std::fmt; use uucore::{ display::Quotable, - parse_size::{parse_size_u64, parse_size_u64_max, ParseSizeError}, + parse_size::{ParseSizeError, parse_size_u64, parse_size_u64_max}, }; /// Sub-strategy of the [`Strategy::Number`] diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 9cd45ca36..706e8157d 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -10,7 +10,7 @@ use clap::builder::ValueParser; use uucore::display::Quotable; use uucore::fs::display_permissions; use uucore::fsext::{ - pretty_filetype, pretty_fstype, read_fs_list, statfs, BirthTime, FsMeta, StatFs, + BirthTime, FsMeta, StatFs, pretty_filetype, pretty_fstype, read_fs_list, statfs, }; use uucore::libc::mode_t; use uucore::{ @@ -1197,7 +1197,7 @@ fn pretty_time(sec: i64, nsec: i64) -> String { #[cfg(test)] mod tests { - use super::{group_num, precision_trunc, Flags, Precision, ScanUtil, Stater, Token}; + use super::{Flags, Precision, ScanUtil, Stater, Token, group_num, precision_trunc}; #[test] fn test_scanners() { diff --git a/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs b/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs index d3e6852a0..b87e94939 100644 --- a/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs +++ b/src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs @@ -5,7 +5,7 @@ // spell-checker:ignore (ToDO) IOFBF IOLBF IONBF cstdio setvbuf use cpp::cpp; -use libc::{c_char, c_int, fileno, size_t, FILE, _IOFBF, _IOLBF, _IONBF}; +use libc::{_IOFBF, _IOLBF, _IONBF, FILE, c_char, c_int, fileno, size_t}; use std::env; use std::ptr; diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 045fafe8c..93d524dbd 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -11,8 +11,8 @@ use std::io::Write; use std::os::unix::process::ExitStatusExt; use std::path::PathBuf; use std::process; -use tempfile::tempdir; use tempfile::TempDir; +use tempfile::tempdir; use uucore::error::{FromIo, UClapError, UResult, USimpleError, UUsageError}; use uucore::parse_size::parse_size_u64; use uucore::{format_usage, help_about, help_section, help_usage}; @@ -171,7 +171,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { format!("{EXEC_ERROR} No such file or directory"), )), _ => Err(USimpleError::new(1, format!("{EXEC_ERROR} {}", e))), - } + }; } }; diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 0b09292c9..ea5eb8e1d 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -8,14 +8,14 @@ mod flags; use clap::{Arg, ArgAction, ArgMatches, Command}; -use nix::libc::{c_ushort, O_NONBLOCK, TIOCGWINSZ, TIOCSWINSZ}; +use nix::libc::{O_NONBLOCK, TIOCGWINSZ, TIOCSWINSZ, c_ushort}; use nix::sys::termios::{ - cfgetospeed, cfsetospeed, tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, - OutputFlags, SpecialCharacterIndices, Termios, + ControlFlags, InputFlags, LocalFlags, OutputFlags, SpecialCharacterIndices, Termios, + cfgetospeed, cfsetospeed, tcgetattr, tcsetattr, }; use nix::{ioctl_read_bad, ioctl_write_ptr_bad}; use std::fs::File; -use std::io::{self, stdout, Stdout}; +use std::io::{self, Stdout, stdout}; use std::ops::ControlFlow; use std::os::fd::{AsFd, BorrowedFd}; use std::os::unix::fs::OpenOptionsExt; diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 8883cd9c9..1b09afca9 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -7,7 +7,7 @@ use clap::{Arg, ArgAction, Command}; use std::fs::File; -use std::io::{stdin, Read}; +use std::io::{Read, stdin}; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 54b299809..4ac3d7881 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -9,7 +9,7 @@ use clap::{Arg, ArgAction, Command}; #[cfg(any(target_os = "linux", target_os = "android"))] use nix::errno::Errno; #[cfg(any(target_os = "linux", target_os = "android"))] -use nix::fcntl::{open, OFlag}; +use nix::fcntl::{OFlag, open}; #[cfg(any(target_os = "linux", target_os = "android"))] use nix::sys::stat::Mode; use std::path::Path; @@ -81,7 +81,7 @@ mod platform { use uucore::error::{UResult, USimpleError}; use uucore::wide::{FromWide, ToWide}; use windows_sys::Win32::Foundation::{ - GetLastError, ERROR_NO_MORE_FILES, HANDLE, INVALID_HANDLE_VALUE, MAX_PATH, + ERROR_NO_MORE_FILES, GetLastError, HANDLE, INVALID_HANDLE_VALUE, MAX_PATH, }; use windows_sys::Win32::Storage::FileSystem::{ FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, FlushFileBuffers, GetDriveTypeW, diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 03653d338..511cfac7e 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -9,9 +9,9 @@ mod error; use clap::{Arg, ArgAction, Command}; use memchr::memmem; use memmap2::Mmap; -use std::io::{stdin, stdout, BufWriter, Read, Write}; +use std::io::{BufWriter, Read, Write, stdin, stdout}; use std::{ - fs::{read, File}, + fs::{File, read}, path::Path, }; use uucore::display::Quotable; diff --git a/src/uu/tail/src/args.rs b/src/uu/tail/src/args.rs index b6b1e93f0..7a7e6c790 100644 --- a/src/uu/tail/src/args.rs +++ b/src/uu/tail/src/args.rs @@ -6,15 +6,15 @@ // spell-checker:ignore (ToDO) kqueue Signum fundu use crate::paths::Input; -use crate::{parse, platform, Quotable}; -use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; +use crate::{Quotable, parse, platform}; +use clap::{Arg, ArgAction, ArgMatches, Command, value_parser}; use fundu::{DurationParser, SaturatingInto}; use same_file::Handle; use std::ffi::OsString; use std::io::IsTerminal; use std::time::Duration; use uucore::error::{UResult, USimpleError, UUsageError}; -use uucore::parse_size::{parse_size_u64, ParseSizeError}; +use uucore::parse_size::{ParseSizeError, parse_size_u64}; use uucore::shortcut_value_parser::ShortcutValueParser; use uucore::{format_usage, help_about, help_usage, show_warning}; @@ -80,7 +80,7 @@ impl FilterMode { return Err(USimpleError::new( 1, format!("invalid number of bytes: '{e}'"), - )) + )); } } } else if let Some(arg) = matches.get_one::(options::LINES) { @@ -93,7 +93,7 @@ impl FilterMode { return Err(USimpleError::new( 1, format!("invalid number of lines: {e}"), - )) + )); } } } else if zero_term { @@ -241,7 +241,7 @@ impl Settings { return Err(UUsageError::new( 1, format!("invalid number of seconds: '{source}'"), - )) + )); } } } diff --git a/src/uu/tail/src/chunks.rs b/src/uu/tail/src/chunks.rs index d4c0b63f8..e8ee761ed 100644 --- a/src/uu/tail/src/chunks.rs +++ b/src/uu/tail/src/chunks.rs @@ -627,7 +627,7 @@ impl LinesChunkBuffer { #[cfg(test)] mod tests { - use crate::chunks::{BytesChunk, BUFFER_SIZE}; + use crate::chunks::{BUFFER_SIZE, BytesChunk}; #[test] fn test_bytes_chunk_from_when_offset_is_zero() { diff --git a/src/uu/tail/src/follow/files.rs b/src/uu/tail/src/follow/files.rs index d1aa0aed6..21af5eb28 100644 --- a/src/uu/tail/src/follow/files.rs +++ b/src/uu/tail/src/follow/files.rs @@ -9,10 +9,10 @@ use crate::args::Settings; use crate::chunks::BytesChunkBuffer; use crate::paths::{HeaderPrinter, PathExtTail}; use crate::text; -use std::collections::hash_map::Keys; use std::collections::HashMap; +use std::collections::hash_map::Keys; use std::fs::{File, Metadata}; -use std::io::{stdout, BufRead, BufReader, BufWriter}; +use std::io::{BufRead, BufReader, BufWriter, stdout}; use std::path::{Path, PathBuf}; use uucore::error::UResult; diff --git a/src/uu/tail/src/follow/mod.rs b/src/uu/tail/src/follow/mod.rs index 52eef318f..604602a4b 100644 --- a/src/uu/tail/src/follow/mod.rs +++ b/src/uu/tail/src/follow/mod.rs @@ -6,4 +6,4 @@ mod files; mod watch; -pub use watch::{follow, Observer}; +pub use watch::{Observer, follow}; diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index b74e5c108..f6d5beadc 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -12,9 +12,9 @@ use crate::{platform, text}; use notify::{RecommendedWatcher, RecursiveMode, Watcher, WatcherKind}; use std::io::BufRead; use std::path::{Path, PathBuf}; -use std::sync::mpsc::{self, channel, Receiver}; +use std::sync::mpsc::{self, Receiver, channel}; use uucore::display::Quotable; -use uucore::error::{set_exit_code, UResult, USimpleError}; +use uucore::error::{UResult, USimpleError, set_exit_code}; use uucore::show_error; pub struct WatcherRx { @@ -566,7 +566,7 @@ pub fn follow(mut observer: Observer, settings: &Settings) -> UResult<()> { return Err(USimpleError::new( 1, format!("{} resources exhausted", text::BACKEND), - )) + )); } Ok(Err(e)) => return Err(USimpleError::new(1, format!("NotifyError: {e}"))), Err(mpsc::RecvTimeoutError::Timeout) => { diff --git a/src/uu/tail/src/platform/mod.rs b/src/uu/tail/src/platform/mod.rs index cd2953ffd..d3220491f 100644 --- a/src/uu/tail/src/platform/mod.rs +++ b/src/uu/tail/src/platform/mod.rs @@ -5,14 +5,14 @@ #[cfg(unix)] pub use self::unix::{ - //stdin_is_bad_fd, stdin_is_pipe_or_fifo, supports_pid_checks, Pid, ProcessChecker, - supports_pid_checks, Pid, ProcessChecker, + //stdin_is_bad_fd, stdin_is_pipe_or_fifo, supports_pid_checks, Pid, ProcessChecker, + supports_pid_checks, }; #[cfg(windows)] -pub use self::windows::{supports_pid_checks, Pid, ProcessChecker}; +pub use self::windows::{Pid, ProcessChecker, supports_pid_checks}; #[cfg(unix)] mod unix; diff --git a/src/uu/tail/src/platform/windows.rs b/src/uu/tail/src/platform/windows.rs index d6e0828c9..e3b236b12 100644 --- a/src/uu/tail/src/platform/windows.rs +++ b/src/uu/tail/src/platform/windows.rs @@ -3,9 +3,9 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use windows_sys::Win32::Foundation::{CloseHandle, BOOL, HANDLE, WAIT_FAILED, WAIT_OBJECT_0}; +use windows_sys::Win32::Foundation::{BOOL, CloseHandle, HANDLE, WAIT_FAILED, WAIT_OBJECT_0}; use windows_sys::Win32::System::Threading::{ - OpenProcess, WaitForSingleObject, PROCESS_SYNCHRONIZE, + OpenProcess, PROCESS_SYNCHRONIZE, WaitForSingleObject, }; pub type Pid = u32; diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index a48da6b31..11af1a685 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -21,17 +21,17 @@ mod platform; pub mod text; pub use args::uu_app; -use args::{parse_args, FilterMode, Settings, Signum}; +use args::{FilterMode, Settings, Signum, parse_args}; use chunks::ReverseChunks; use follow::Observer; use paths::{FileExtTail, HeaderPrinter, Input, InputKind, MetadataExtTail}; use same_file::Handle; use std::cmp::Ordering; use std::fs::File; -use std::io::{self, stdin, stdout, BufRead, BufReader, BufWriter, Read, Seek, SeekFrom, Write}; +use std::io::{self, BufRead, BufReader, BufWriter, Read, Seek, SeekFrom, Write, stdin, stdout}; use std::path::{Path, PathBuf}; use uucore::display::Quotable; -use uucore::error::{get_exit_code, set_exit_code, FromIo, UResult, USimpleError}; +use uucore::error::{FromIo, UResult, USimpleError, get_exit_code, set_exit_code}; use uucore::{show, show_error}; #[uucore::main] @@ -45,7 +45,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(USimpleError::new( 1, format!("cannot follow {} by name", text::DASH.quote()), - )) + )); } // Exit early if we do not output anything. Note, that this may break a pipe // when tail is on the receiving side. diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 2666fc214..e2517cf73 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -5,9 +5,9 @@ // cSpell:ignore POLLERR POLLRDBAND pfds revents -use clap::{builder::PossibleValue, Arg, ArgAction, Command}; +use clap::{Arg, ArgAction, Command, builder::PossibleValue}; use std::fs::OpenOptions; -use std::io::{copy, stdin, stdout, Error, ErrorKind, Read, Result, Write}; +use std::io::{Error, ErrorKind, Read, Result, Write, copy, stdin, stdout}; use std::path::PathBuf; use uucore::display::Quotable; use uucore::error::UResult; @@ -391,7 +391,7 @@ impl Read for NamedReader { pub fn ensure_stdout_not_broken() -> Result { use nix::{ poll::{PollFd, PollFlags, PollTimeout}, - sys::stat::{fstat, SFlag}, + sys::stat::{SFlag, fstat}, }; use std::os::fd::{AsFd, AsRawFd}; diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index b910010d6..9765e73d5 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -10,7 +10,7 @@ mod parser; use clap::Command; use error::{ParseError, ParseResult}; -use parser::{parse, Operator, Symbol, UnaryOperator}; +use parser::{Operator, Symbol, UnaryOperator, parse}; use std::ffi::{OsStr, OsString}; use std::fs; #[cfg(unix)] @@ -69,11 +69,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { let result = parse(args).map(|mut stack| eval(&mut stack))??; - if result { - Ok(()) - } else { - Err(1.into()) - } + if result { Ok(()) } else { Err(1.into()) } } /// Evaluate a stack of Symbols, returning the result of the evaluation or diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index 339397109..e32d784e2 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -60,7 +60,7 @@ impl Config { return Err(UUsageError::new( ExitStatus::TimeoutFailed.into(), format!("{}: invalid signal", signal_.quote()), - )) + )); } Some(signal_value) => signal_value, } diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 1fa45d8a4..dd155b44e 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -14,7 +14,7 @@ use chrono::{ }; use clap::builder::{PossibleValue, ValueParser}; use clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command}; -use filetime::{set_file_times, set_symlink_file_times, FileTime}; +use filetime::{FileTime, set_file_times, set_symlink_file_times}; use std::borrow::Cow; use std::ffi::OsString; use std::fs::{self, File}; @@ -681,7 +681,7 @@ fn parse_timestamp(s: &str) -> UResult { return Err(USimpleError::new( 1, format!("invalid date format {}", s.quote()), - )) + )); } }; @@ -736,11 +736,11 @@ fn pathbuf_from_stdout() -> Result { { use std::os::windows::prelude::AsRawHandle; use windows_sys::Win32::Foundation::{ - GetLastError, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, ERROR_PATH_NOT_FOUND, + ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, ERROR_PATH_NOT_FOUND, GetLastError, HANDLE, MAX_PATH, }; use windows_sys::Win32::Storage::FileSystem::{ - GetFinalPathNameByHandleW, FILE_NAME_OPENED, + FILE_NAME_OPENED, GetFinalPathNameByHandleW, }; let handle = std::io::stdout().lock().as_raw_handle() as HANDLE; @@ -767,7 +767,7 @@ fn pathbuf_from_stdout() -> Result { ERROR_PATH_NOT_FOUND | ERROR_NOT_ENOUGH_MEMORY | ERROR_INVALID_PARAMETER => { return Err(TouchError::WindowsStdoutPathError(format!( "GetFinalPathNameByHandleW failed with code {ret}" - ))) + ))); } 0 => { return Err(TouchError::WindowsStdoutPathError(format!( @@ -791,8 +791,8 @@ mod tests { use filetime::FileTime; use crate::{ - determine_atime_mtime_change, error::TouchError, touch, uu_app, ChangeTimes, Options, - Source, + ChangeTimes, Options, Source, determine_atime_mtime_change, error::TouchError, touch, + uu_app, }; #[cfg(windows)] @@ -800,10 +800,12 @@ mod tests { fn test_get_pathbuf_from_stdout_fails_if_stdout_is_not_a_file() { // We can trigger an error by not setting stdout to anything (will // fail with code 1) - assert!(super::pathbuf_from_stdout() - .expect_err("pathbuf_from_stdout should have failed") - .to_string() - .contains("GetFinalPathNameByHandleW failed with code 1")); + assert!( + super::pathbuf_from_stdout() + .expect_err("pathbuf_from_stdout should have failed") + .to_string() + .contains("GetFinalPathNameByHandleW failed with code 1") + ); } #[test] diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index 6fbb2d57e..ae01c61ec 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -7,13 +7,13 @@ use crate::unicode_table; use nom::{ + IResult, Parser, branch::alt, bytes::complete::{tag, take, take_till, take_until}, character::complete::one_of, combinator::{map, map_opt, peek, recognize, value}, - multi::{many0, many_m_n}, + multi::{many_m_n, many0}, sequence::{delimited, preceded, separated_pair, terminated}, - IResult, Parser, }; use std::{ char, @@ -62,16 +62,28 @@ impl Display for BadSequence { write!(f, "when not truncating set1, string2 must be non-empty") } Self::ClassExceptLowerUpperInSet2 => { - write!(f, "when translating, the only character classes that may appear in set2 are 'upper' and 'lower'") + write!( + f, + "when translating, the only character classes that may appear in set2 are 'upper' and 'lower'" + ) } Self::ClassInSet2NotMatchedBySet1 => { - write!(f, "when translating, every 'upper'/'lower' in set2 must be matched by a 'upper'/'lower' in the same position in set1") + write!( + f, + "when translating, every 'upper'/'lower' in set2 must be matched by a 'upper'/'lower' in the same position in set1" + ) } Self::Set1LongerSet2EndsInClass => { - write!(f, "when translating with string1 longer than string2,\nthe latter string must not end with a character class") + write!( + f, + "when translating with string1 longer than string2,\nthe latter string must not end with a character class" + ) } Self::ComplementMoreThanOneUniqueInSet2 => { - write!(f, "when translating with complemented character classes,\nstring2 must map all characters in the domain to one") + write!( + f, + "when translating with complemented character classes,\nstring2 must map all characters in the domain to one" + ) } Self::BackwardsRange { end, start } => { fn end_or_start_to_string(ut: &u32) -> String { @@ -505,11 +517,7 @@ impl Sequence { map(Self::parse_backslash_or_char, Ok), )), map(terminated(take_until("=]"), tag("=]")), |v: &[u8]| { - if v.is_empty() { - Ok(()) - } else { - Err(v) - } + if v.is_empty() { Ok(()) } else { Err(v) } }), ), ) diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 563d02d6a..068d3bd03 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -9,12 +9,12 @@ mod operation; mod unicode_table; use crate::operation::DeleteOperation; -use clap::{value_parser, Arg, ArgAction, Command}; +use clap::{Arg, ArgAction, Command, value_parser}; use operation::{ - translate_input, Sequence, SqueezeOperation, SymbolTranslator, TranslateOperation, + Sequence, SqueezeOperation, SymbolTranslator, TranslateOperation, translate_input, }; use std::ffi::OsString; -use std::io::{stdin, stdout, BufWriter}; +use std::io::{BufWriter, stdin, stdout}; use uucore::display::Quotable; use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::fs::is_stdin_directory; diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index 608895c14..f99a4c7ae 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use clap::{Arg, ArgAction, Command}; use std::{ffi::OsString, io::Write}; -use uucore::error::{set_exit_code, UResult}; +use uucore::error::{UResult, set_exit_code}; use uucore::help_about; const ABOUT: &str = help_about!("true.md"); diff --git a/src/uu/truncate/src/truncate.rs b/src/uu/truncate/src/truncate.rs index a887e0e27..ac4cb7c3c 100644 --- a/src/uu/truncate/src/truncate.rs +++ b/src/uu/truncate/src/truncate.rs @@ -5,14 +5,14 @@ // spell-checker:ignore (ToDO) RFILE refsize rfilename fsize tsize use clap::{Arg, ArgAction, Command}; -use std::fs::{metadata, OpenOptions}; +use std::fs::{OpenOptions, metadata}; use std::io::ErrorKind; #[cfg(unix)] use std::os::unix::fs::FileTypeExt; use std::path::Path; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; -use uucore::parse_size::{parse_size_u64, ParseSizeError}; +use uucore::parse_size::{ParseSizeError, parse_size_u64}; use uucore::{format_usage, help_about, help_section, help_usage}; #[derive(Debug, Eq, PartialEq)] @@ -229,7 +229,7 @@ fn truncate_reference_and_size( return Err(USimpleError::new( 1, String::from("you must specify a relative '--size' with '--reference'"), - )) + )); } Ok(m) => m, }; @@ -408,8 +408,8 @@ fn parse_mode_and_size(size_string: &str) -> Result Graph<'input> { }) .collect(); independent_nodes_queue.make_contiguous().sort_unstable(); // to make sure the resulting ordering is deterministic we need to order independent nodes - // FIXME: this doesn't comply entirely with the GNU coreutils implementation. + // FIXME: this doesn't comply entirely with the GNU coreutils implementation. // To make sure the resulting ordering is deterministic we // need to order independent nodes. diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 10428f85e..35dc1f086 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -9,7 +9,7 @@ use clap::{Arg, ArgAction, Command}; use std::io::{IsTerminal, Write}; -use uucore::error::{set_exit_code, UResult}; +use uucore::error::{UResult, set_exit_code}; use uucore::{format_usage, help_about, help_usage}; const ABOUT: &str = help_about!("tty.md"); diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 85267f08e..07abe456f 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -9,7 +9,7 @@ use clap::{Arg, ArgAction, Command}; use std::error::Error; use std::fmt; use std::fs::File; -use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Stdout, Write}; +use std::io::{BufRead, BufReader, BufWriter, Read, Stdout, Write, stdin, stdout}; use std::num::IntErrorKind; use std::path::Path; use std::str::from_utf8; @@ -60,7 +60,7 @@ fn tabstops_parse(s: &str) -> Result, ParseError> { _ => { return Err(ParseError::InvalidCharacter( word.trim_start_matches(char::is_numeric).to_string(), - )) + )); } }, } diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 911aa9b7e..744ff6d99 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -4,16 +4,16 @@ // file that was distributed with this source code. // spell-checker:ignore badoption use clap::{ - builder::ValueParser, error::ContextKind, error::Error, error::ErrorKind, Arg, ArgAction, - ArgMatches, Command, + Arg, ArgAction, ArgMatches, Command, builder::ValueParser, error::ContextKind, error::Error, + error::ErrorKind, }; use std::ffi::{OsStr, OsString}; use std::fs::File; -use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Write}; +use std::io::{BufRead, BufReader, BufWriter, Write, stdin, stdout}; use std::num::IntErrorKind; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError}; -use uucore::posix::{posix_version, OBSOLETE}; +use uucore::posix::{OBSOLETE, posix_version}; use uucore::shortcut_value_parser::ShortcutValueParser; use uucore::{format_usage, help_about, help_section, help_usage}; @@ -139,11 +139,7 @@ impl Uniq { } fn get_line_terminator(&self) -> u8 { - if self.zero_terminated { - 0 - } else { - b'\n' - } + if self.zero_terminated { 0 } else { b'\n' } } fn cmp_keys(&self, first: &[u8], second: &[u8]) -> bool { diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index 6f4dc2f81..05d00f7f8 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -15,7 +15,7 @@ use uucore::uptime::*; use uucore::error::UResult; -use clap::{builder::ValueParser, Arg, ArgAction, Command, ValueHint}; +use clap::{Arg, ArgAction, Command, ValueHint, builder::ValueParser}; use uucore::{format_usage, help_about, help_usage}; diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index 4c94ea471..3ca4b26f5 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -14,7 +14,7 @@ use uucore::error::UResult; use uucore::{format_usage, help_about, help_usage}; #[cfg(target_os = "openbsd")] -use utmp_classic::{parse_from_path, UtmpEntry}; +use utmp_classic::{UtmpEntry, parse_from_path}; #[cfg(not(target_os = "openbsd"))] use uucore::utmpx::{self, Utmpx}; diff --git a/src/uu/vdir/src/vdir.rs b/src/uu/vdir/src/vdir.rs index b9d80c401..fbb8943ca 100644 --- a/src/uu/vdir/src/vdir.rs +++ b/src/uu/vdir/src/vdir.rs @@ -6,7 +6,7 @@ use clap::Command; use std::ffi::OsString; use std::path::Path; -use uu_ls::{options, Config, Format}; +use uu_ls::{Config, Format, options}; use uucore::error::UResult; use uucore::quoting_style::{Quotes, QuotingStyle}; diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index 843ff4b2f..b79e6b0e3 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -13,7 +13,7 @@ use std::fs::OpenOptions; use std::io::{self, ErrorKind, Read}; #[cfg(unix)] -use libc::{sysconf, S_IFREG, _SC_PAGESIZE}; +use libc::{_SC_PAGESIZE, S_IFREG, sysconf}; #[cfg(unix)] use nix::sys::stat; #[cfg(unix)] diff --git a/src/uu/wc/src/utf8/read.rs b/src/uu/wc/src/utf8/read.rs index 9515cdc9f..3556436f9 100644 --- a/src/uu/wc/src/utf8/read.rs +++ b/src/uu/wc/src/utf8/read.rs @@ -99,7 +99,7 @@ impl BufReadDecoder { } match error.error_len() { Some(invalid_sequence_length) => { - break (BytesSource::BufRead(invalid_sequence_length), Err(())) + break (BytesSource::BufRead(invalid_sequence_length), Err(())); } None => { self.bytes_consumed = buf.len(); diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 6167159c0..0d5df7b65 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -20,7 +20,7 @@ use std::{ path::{Path, PathBuf}, }; -use clap::{builder::ValueParser, Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser}; use thiserror::Error; use unicode_width::UnicodeWidthChar; use utf8::{BufReadDecoder, BufReadDecoderError}; diff --git a/src/uu/who/src/platform/unix.rs b/src/uu/who/src/platform/unix.rs index b59b73a57..b173256cf 100644 --- a/src/uu/who/src/platform/unix.rs +++ b/src/uu/who/src/platform/unix.rs @@ -10,8 +10,8 @@ use crate::uu_app; use uucore::display::Quotable; use uucore::error::{FromIo, UResult}; -use uucore::libc::{ttyname, STDIN_FILENO, S_IWGRP}; -use uucore::utmpx::{self, time, Utmpx}; +use uucore::libc::{S_IWGRP, STDIN_FILENO, ttyname}; +use uucore::utmpx::{self, Utmpx, time}; use std::borrow::Cow; use std::ffi::CStr; diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index 6eef65917..d9bbc64e4 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -5,7 +5,7 @@ // cSpell:ignore strs -use clap::{builder::ValueParser, Arg, ArgAction, Command}; +use clap::{Arg, ArgAction, Command, builder::ValueParser}; use std::error::Error; use std::ffi::OsString; use std::io::{self, Write}; diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 7de10f55b..e56eedd4b 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -12,7 +12,7 @@ use std::{ ffi::OsStr, fmt::Display, fs::File, - io::{self, stdin, BufReader, Read, Write}, + io::{self, BufReader, Read, Write, stdin}, path::Path, str, sync::LazyLock, @@ -22,8 +22,8 @@ use crate::{ error::{FromIo, UError, UResult, USimpleError}, os_str_as_bytes, os_str_from_bytes, read_os_string_lines, show, show_error, show_warning_caps, sum::{ - Blake2b, Blake3, Digest, DigestWriter, Md5, Sha1, Sha224, Sha256, Sha384, Sha3_224, - Sha3_256, Sha3_384, Sha3_512, Sha512, Shake128, Shake256, Sm3, BSD, CRC, CRC32B, SYSV, + BSD, Blake2b, Blake3, CRC, CRC32B, Digest, DigestWriter, Md5, SYSV, Sha1, Sha3_224, + Sha3_256, Sha3_384, Sha3_512, Sha224, Sha256, Sha384, Sha512, Shake128, Shake256, Sm3, }, util_name, }; @@ -603,11 +603,7 @@ fn get_expected_digest_as_hex_string( .ok() .and_then(|s| { // Check the digest length - if against_hint(s.len()) { - Some(s) - } else { - None - } + if against_hint(s.len()) { Some(s) } else { None } }) } diff --git a/src/uucore/src/lib/features/format/argument.rs b/src/uucore/src/lib/features/format/argument.rs index 5cdd03421..08111bca8 100644 --- a/src/uucore/src/lib/features/format/argument.rs +++ b/src/uucore/src/lib/features/format/argument.rs @@ -6,7 +6,7 @@ use crate::{ error::set_exit_code, features::format::num_parser::{ParseError, ParsedNumber}, - quoting_style::{escape_name, Quotes, QuotingStyle}, + quoting_style::{Quotes, QuotingStyle, escape_name}, show_error, show_warning, }; use os_display::Quotable; diff --git a/src/uucore/src/lib/features/format/mod.rs b/src/uucore/src/lib/features/format/mod.rs index 25a4449dc..4a0a1a979 100644 --- a/src/uucore/src/lib/features/format/mod.rs +++ b/src/uucore/src/lib/features/format/mod.rs @@ -45,7 +45,7 @@ pub use spec::Spec; use std::{ error::Error, fmt::Display, - io::{stdout, Write}, + io::{Write, stdout}, marker::PhantomData, ops::ControlFlow, }; @@ -55,7 +55,7 @@ use os_display::Quotable; use crate::error::UError; pub use self::{ - escape::{parse_escape_code, EscapedChar, OctalParsing}, + escape::{EscapedChar, OctalParsing, parse_escape_code}, num_format::Formatter, }; diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index e157fa5ec..d91f86fd1 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -5,16 +5,16 @@ // spell-checker:ignore bigdecimal prec //! Utilities for formatting numbers in various formats -use bigdecimal::num_bigint::ToBigInt; use bigdecimal::BigDecimal; +use bigdecimal::num_bigint::ToBigInt; use num_traits::Signed; use num_traits::Zero; use std::cmp::min; use std::io::Write; use super::{ - spec::{CanAsterisk, Spec}, ExtendedBigDecimal, FormatError, + spec::{CanAsterisk, Spec}, }; pub trait Formatter { @@ -656,8 +656,8 @@ mod test { use std::str::FromStr; use crate::format::{ - num_format::{Case, ForceDecimal}, ExtendedBigDecimal, + num_format::{Case, ForceDecimal}, }; #[test] diff --git a/src/uucore/src/lib/features/format/num_parser.rs b/src/uucore/src/lib/features/format/num_parser.rs index b19c3d72f..7de3a0e0a 100644 --- a/src/uucore/src/lib/features/format/num_parser.rs +++ b/src/uucore/src/lib/features/format/num_parser.rs @@ -122,11 +122,7 @@ impl ParsedNumber { fn into_f64(self) -> f64 { let n = self.integral as f64 + (self.fractional as f64) / (self.base as u8 as f64).powf(self.precision as f64); - if self.negative { - -n - } else { - n - } + if self.negative { -n } else { n } } /// Parse a number as f64 diff --git a/src/uucore/src/lib/features/format/spec.rs b/src/uucore/src/lib/features/format/spec.rs index 190a4f2f0..63b3dd221 100644 --- a/src/uucore/src/lib/features/format/spec.rs +++ b/src/uucore/src/lib/features/format/spec.rs @@ -5,14 +5,15 @@ // spell-checker:ignore (vars) intmax ptrdiff padlen -use crate::quoting_style::{escape_name, QuotingStyle}; +use crate::quoting_style::{QuotingStyle, escape_name}; use super::{ + ArgumentIter, ExtendedBigDecimal, FormatChar, FormatError, OctalParsing, num_format::{ self, Case, FloatVariant, ForceDecimal, Formatter, NumberAlignment, PositiveSign, Prefix, UnsignedIntVariant, }, - parse_escape_only, ArgumentIter, ExtendedBigDecimal, FormatChar, FormatError, OctalParsing, + parse_escape_only, }; use std::{io::Write, ops::ControlFlow}; diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 8ef645cfb..d70fb7822 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -9,9 +9,9 @@ #[cfg(unix)] use libc::{ - mode_t, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, S_IRGRP, - S_IROTH, S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, - S_IXUSR, + S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, S_IRGRP, S_IROTH, + S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR, + mode_t, }; use std::collections::HashSet; use std::collections::VecDeque; @@ -24,7 +24,7 @@ use std::io::Stdin; use std::io::{Error, ErrorKind, Result as IOResult}; #[cfg(unix)] use std::os::unix::{fs::MetadataExt, io::AsRawFd}; -use std::path::{Component, Path, PathBuf, MAIN_SEPARATOR}; +use std::path::{Component, MAIN_SEPARATOR, Path, PathBuf}; #[cfg(target_os = "windows")] use winapi_util::AsHandleRef; @@ -500,11 +500,7 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String result.push(if has!(mode, S_IRUSR) { 'r' } else { '-' }); result.push(if has!(mode, S_IWUSR) { 'w' } else { '-' }); result.push(if has!(mode, S_ISUID as mode_t) { - if has!(mode, S_IXUSR) { - 's' - } else { - 'S' - } + if has!(mode, S_IXUSR) { 's' } else { 'S' } } else if has!(mode, S_IXUSR) { 'x' } else { @@ -514,11 +510,7 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String result.push(if has!(mode, S_IRGRP) { 'r' } else { '-' }); result.push(if has!(mode, S_IWGRP) { 'w' } else { '-' }); result.push(if has!(mode, S_ISGID as mode_t) { - if has!(mode, S_IXGRP) { - 's' - } else { - 'S' - } + if has!(mode, S_IXGRP) { 's' } else { 'S' } } else if has!(mode, S_IXGRP) { 'x' } else { @@ -528,11 +520,7 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String result.push(if has!(mode, S_IROTH) { 'r' } else { '-' }); result.push(if has!(mode, S_IWOTH) { 'w' } else { '-' }); result.push(if has!(mode, S_ISVTX as mode_t) { - if has!(mode, S_IXOTH) { - 't' - } else { - 'T' - } + if has!(mode, S_IXOTH) { 't' } else { 'T' } } else if has!(mode, S_IXOTH) { 'x' } else { @@ -819,7 +807,7 @@ mod tests { #[cfg(unix)] use std::os::unix; #[cfg(unix)] - use tempfile::{tempdir, NamedTempFile}; + use tempfile::{NamedTempFile, tempdir}; struct NormalizePathTestCase<'a> { path: &'a str, diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 83eca0fa0..c0d065980 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -59,7 +59,7 @@ fn to_nul_terminated_wide_string(s: impl AsRef) -> Vec { #[cfg(unix)] use libc::{ - mode_t, strerror, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, + S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK, mode_t, strerror, }; use std::borrow::Cow; #[cfg(unix)] diff --git a/src/uucore/src/lib/features/mode.rs b/src/uucore/src/lib/features/mode.rs index 9a7336b34..5a0a51727 100644 --- a/src/uucore/src/lib/features/mode.rs +++ b/src/uucore/src/lib/features/mode.rs @@ -7,7 +7,7 @@ // spell-checker:ignore (vars) fperm srwx -use libc::{mode_t, umask, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR}; +use libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, mode_t, umask}; pub fn parse_numeric(fperm: u32, mut mode: &str, considering_dir: bool) -> Result { let (op, pos) = parse_op(mode).map_or_else(|_| (None, 0), |(op, pos)| (Some(op), pos)); diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 3879b7337..4addccf24 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -8,7 +8,7 @@ // spell-checker:ignore (jargon) TOCTOU use crate::display::Quotable; -use crate::error::{strip_errno, UResult, USimpleError}; +use crate::error::{UResult, USimpleError, strip_errno}; pub use crate::features::entries; use crate::show_error; use clap::{Arg, ArgMatches, Command}; @@ -24,7 +24,7 @@ use std::fs::Metadata; use std::os::unix::fs::MetadataExt; use std::os::unix::ffi::OsStrExt; -use std::path::{Path, MAIN_SEPARATOR}; +use std::path::{MAIN_SEPARATOR, Path}; /// The various level of verbosity #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/src/uucore/src/lib/features/quoting_style.rs b/src/uucore/src/lib/features/quoting_style.rs index 6d0265dc6..42d39a104 100644 --- a/src/uucore/src/lib/features/quoting_style.rs +++ b/src/uucore/src/lib/features/quoting_style.rs @@ -512,7 +512,7 @@ impl fmt::Display for Quotes { #[cfg(test)] mod tests { - use crate::quoting_style::{escape_name_inner, Quotes, QuotingStyle}; + use crate::quoting_style::{Quotes, QuotingStyle, escape_name_inner}; // spell-checker:ignore (tests/words) one\'two one'two @@ -852,14 +852,26 @@ mod tests { &[ ("????????????????", "literal"), (test_str, "literal-show"), - ("\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217", "escape"), - ("\"\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217\"", "c"), + ( + "\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217", + "escape", + ), + ( + "\"\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217\"", + "c", + ), ("????????????????", "shell"), (test_str, "shell-show"), ("'????????????????'", "shell-always"), (&format!("'{}'", test_str), "shell-always-show"), - ("''$'\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217'", "shell-escape"), - ("''$'\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217'", "shell-escape-always"), + ( + "''$'\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217'", + "shell-escape", + ), + ( + "''$'\\302\\200\\302\\201\\302\\202\\302\\203\\302\\204\\302\\205\\302\\206\\302\\207\\302\\210\\302\\211\\302\\212\\302\\213\\302\\214\\302\\215\\302\\216\\302\\217'", + "shell-escape-always", + ), ], ); @@ -870,14 +882,26 @@ mod tests { &[ ("????????????????", "literal"), (test_str, "literal-show"), - ("\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237", "escape"), - ("\"\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237\"", "c"), + ( + "\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237", + "escape", + ), + ( + "\"\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237\"", + "c", + ), ("????????????????", "shell"), (test_str, "shell-show"), ("'????????????????'", "shell-always"), (&format!("'{}'", test_str), "shell-always-show"), - ("''$'\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237'", "shell-escape"), - ("''$'\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237'", "shell-escape-always"), + ( + "''$'\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237'", + "shell-escape", + ), + ( + "''$'\\302\\220\\302\\221\\302\\222\\302\\223\\302\\224\\302\\225\\302\\226\\302\\227\\302\\230\\302\\231\\302\\232\\302\\233\\302\\234\\302\\235\\302\\236\\302\\237'", + "shell-escape-always", + ), ], ); } diff --git a/src/uucore/src/lib/features/ranges.rs b/src/uucore/src/lib/features/ranges.rs index 88851b9aa..2e642769f 100644 --- a/src/uucore/src/lib/features/ranges.rs +++ b/src/uucore/src/lib/features/ranges.rs @@ -165,7 +165,7 @@ pub fn contain(ranges: &[Range], n: usize) -> bool { #[cfg(test)] mod test { - use super::{complement, Range}; + use super::{Range, complement}; use std::str::FromStr; fn m(a: Vec, b: &[Range]) { diff --git a/src/uucore/src/lib/features/signals.rs b/src/uucore/src/lib/features/signals.rs index de383a2bd..713aef002 100644 --- a/src/uucore/src/lib/features/signals.rs +++ b/src/uucore/src/lib/features/signals.rs @@ -14,7 +14,7 @@ use nix::errno::Errno; #[cfg(unix)] use nix::sys::signal::{ - signal, SigHandler::SigDfl, SigHandler::SigIgn, Signal::SIGINT, Signal::SIGPIPE, + SigHandler::SigDfl, SigHandler::SigIgn, Signal::SIGINT, Signal::SIGPIPE, signal, }; /// The default signal value. diff --git a/src/uucore/src/lib/features/uptime.rs b/src/uucore/src/lib/features/uptime.rs index ef4f098fc..9f7f9a8ef 100644 --- a/src/uucore/src/lib/features/uptime.rs +++ b/src/uucore/src/lib/features/uptime.rs @@ -51,8 +51,8 @@ pub fn get_formatted_time() -> String { /// Returns a UResult with the uptime in seconds if successful, otherwise an UptimeError. #[cfg(target_os = "openbsd")] pub fn get_uptime(_boot_time: Option) -> UResult { - use libc::clock_gettime; use libc::CLOCK_BOOTTIME; + use libc::clock_gettime; use libc::c_int; use libc::timespec; @@ -209,7 +209,7 @@ pub fn get_nusers() -> usize { /// Returns the number of users currently logged in if successful, otherwise 0 #[cfg(target_os = "openbsd")] pub fn get_nusers(file: &str) -> usize { - use utmp_classic::{parse_from_path, UtmpEntry}; + use utmp_classic::{UtmpEntry, parse_from_path}; let mut nusers = 0; diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index e79ee0572..46bc6d828 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -70,20 +70,20 @@ macro_rules! chars2string { mod ut { pub static DEFAULT_FILE: &str = "/var/run/utmp"; - #[cfg(target_env = "musl")] - pub use libc::UT_HOSTSIZE; #[cfg(not(target_env = "musl"))] pub use libc::__UT_HOSTSIZE as UT_HOSTSIZE; - #[cfg(target_env = "musl")] - pub use libc::UT_LINESIZE; + pub use libc::UT_HOSTSIZE; + #[cfg(not(target_env = "musl"))] pub use libc::__UT_LINESIZE as UT_LINESIZE; - #[cfg(target_env = "musl")] - pub use libc::UT_NAMESIZE; + pub use libc::UT_LINESIZE; + #[cfg(not(target_env = "musl"))] pub use libc::__UT_NAMESIZE as UT_NAMESIZE; + #[cfg(target_env = "musl")] + pub use libc::UT_NAMESIZE; pub const UT_IDSIZE: usize = 4; @@ -238,7 +238,7 @@ impl Utmpx { let (hostname, display) = host.split_once(':').unwrap_or((&host, "")); if !hostname.is_empty() { - use dns_lookup::{getaddrinfo, AddrInfoHints}; + use dns_lookup::{AddrInfoHints, getaddrinfo}; const AI_CANONNAME: i32 = 0x2; let hints = AddrInfoHints { diff --git a/src/uucore/src/lib/features/version_cmp.rs b/src/uucore/src/lib/features/version_cmp.rs index 0819adb75..a9497dcbe 100644 --- a/src/uucore/src/lib/features/version_cmp.rs +++ b/src/uucore/src/lib/features/version_cmp.rs @@ -22,10 +22,10 @@ fn version_non_digit_cmp(a: &str, b: &str) -> Ordering { (None, Some(_)) => return Ordering::Less, (Some(_), None) => return Ordering::Greater, (Some(c1), Some(c2)) if c1.is_ascii_alphabetic() && !c2.is_ascii_alphabetic() => { - return Ordering::Less + return Ordering::Less; } (Some(c1), Some(c2)) if !c1.is_ascii_alphabetic() && c2.is_ascii_alphabetic() => { - return Ordering::Greater + return Ordering::Greater; } (Some(c1), Some(c2)) => return c1.cmp(&c2), } diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index e6d98b695..8cdd1319f 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -112,7 +112,7 @@ pub use crate::features::fsxattr; use nix::errno::Errno; #[cfg(unix)] use nix::sys::signal::{ - sigaction, SaFlags, SigAction, SigHandler::SigDfl, SigSet, Signal::SIGBUS, Signal::SIGSEGV, + SaFlags, SigAction, SigHandler::SigDfl, SigSet, Signal::SIGBUS, Signal::SIGSEGV, sigaction, }; use std::borrow::Cow; use std::ffi::{OsStr, OsString}; @@ -121,7 +121,7 @@ use std::iter; #[cfg(unix)] use std::os::unix::ffi::{OsStrExt, OsStringExt}; use std::str; -use std::sync::{atomic::Ordering, LazyLock}; +use std::sync::{LazyLock, atomic::Ordering}; /// Disables the custom signal handlers installed by Rust for stack-overflow handling. With those custom signal handlers processes ignore the first SIGBUS and SIGSEGV signal they receive. /// See for details. diff --git a/src/uucore/src/lib/parser/shortcut_value_parser.rs b/src/uucore/src/lib/parser/shortcut_value_parser.rs index 17c978022..5800a91f8 100644 --- a/src/uucore/src/lib/parser/shortcut_value_parser.rs +++ b/src/uucore/src/lib/parser/shortcut_value_parser.rs @@ -136,7 +136,7 @@ where mod tests { use std::ffi::OsStr; - use clap::{builder::PossibleValue, builder::TypedValueParser, error::ErrorKind, Command}; + use clap::{Command, builder::PossibleValue, builder::TypedValueParser, error::ErrorKind}; use super::ShortcutValueParser; diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index 9a9626bbb..701d63eb4 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -22,12 +22,14 @@ fn test_help() { #[test] fn test_version() { for version_flg in ["-V", "--version"] { - assert!(new_ucmd!() - .arg(version_flg) - .succeeds() - .no_stderr() - .stdout_str() - .starts_with("basename")); + assert!( + new_ucmd!() + .arg(version_flg) + .succeeds() + .no_stderr() + .stdout_str() + .starts_with("basename") + ); } } @@ -97,12 +99,14 @@ fn test_zero_param() { } fn expect_error(input: &[&str]) { - assert!(!new_ucmd!() - .args(input) - .fails() - .no_stdout() - .stderr_str() - .is_empty()); + assert!( + !new_ucmd!() + .args(input) + .fails() + .no_stdout() + .stderr_str() + .is_empty() + ); } #[test] diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index ee89f1639..4f28d0527 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -4,9 +4,9 @@ // file that was distributed with this source code. // spell-checker:ignore NOFILE nonewline cmdline +use crate::common::util::TestScenario; #[cfg(not(windows))] use crate::common::util::vec_of_size; -use crate::common::util::TestScenario; #[cfg(any(target_os = "linux", target_os = "android"))] use rlimit::Resource; #[cfg(target_os = "linux")] diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index 9a081b98d..2af7620ae 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -124,8 +124,7 @@ fn test_preserve_root_symlink() { ] { let (at, mut ucmd) = at_and_ucmd!(); at.symlink_file(d, file); - let expected_error = - "chgrp: it is dangerous to operate recursively on 'test_chgrp_symlink2root' (same as '/')\nchgrp: use --no-preserve-root to override this failsafe\n"; + let expected_error = "chgrp: it is dangerous to operate recursively on 'test_chgrp_symlink2root' (same as '/')\nchgrp: use --no-preserve-root to override this failsafe\n"; ucmd.arg("--preserve-root") .arg("-HR") .arg("bin") diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index 483b2ef75..48a2d7304 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use crate::common::util::{AtPath, TestScenario, UCommand}; -use std::fs::{metadata, set_permissions, OpenOptions, Permissions}; +use std::fs::{OpenOptions, Permissions, metadata, set_permissions}; use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; static TEST_FILE: &str = "file"; @@ -238,8 +238,7 @@ fn test_chmod_ugoa() { fn test_chmod_umask_expected() { let current_umask = uucore::mode::get_umask(); assert_eq!( - current_umask, - 0o022, + current_umask, 0o022, "Unexpected umask value: expected 022 (octal), but got {:03o}. Please adjust the test environment.", current_umask ); diff --git a/tests/by-util/test_chown.rs b/tests/by-util/test_chown.rs index 44f164380..a13b5dad0 100644 --- a/tests/by-util/test_chown.rs +++ b/tests/by-util/test_chown.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore (words) agroupthatdoesntexist auserthatdoesntexist cuuser groupname notexisting passgrp -use crate::common::util::{is_ci, run_ucmd_as_root, CmdResult, TestScenario}; +use crate::common::util::{CmdResult, TestScenario, is_ci, run_ucmd_as_root}; #[cfg(any(target_os = "linux", target_os = "android"))] use uucore::process::geteuid; diff --git a/tests/by-util/test_chroot.rs b/tests/by-util/test_chroot.rs index b416757f8..cd3f4eecc 100644 --- a/tests/by-util/test_chroot.rs +++ b/tests/by-util/test_chroot.rs @@ -6,7 +6,7 @@ #[cfg(not(target_os = "android"))] use crate::common::util::is_ci; -use crate::common::util::{run_ucmd_as_root, TestScenario}; +use crate::common::util::{TestScenario, run_ucmd_as_root}; #[test] fn test_invalid_arg() { @@ -17,9 +17,11 @@ fn test_invalid_arg() { fn test_missing_operand() { let result = new_ucmd!().fails_with_code(125); - assert!(result - .stderr_str() - .starts_with("error: the following required arguments were not provided")); + assert!( + result + .stderr_str() + .starts_with("error: the following required arguments were not provided") + ); assert!(result.stderr_str().contains("")); } @@ -33,9 +35,11 @@ fn test_enter_chroot_fails() { at.mkdir("jail"); let result = ucmd.arg("jail").fails_with_code(125); - assert!(result - .stderr_str() - .starts_with("chroot: cannot chroot to 'jail': Operation not permitted (os error 1)")); + assert!( + result + .stderr_str() + .starts_with("chroot: cannot chroot to 'jail': Operation not permitted (os error 1)") + ); } #[test] diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 0d79caf19..97761d5bf 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -966,29 +966,41 @@ fn test_cksum_check_failed() { .arg("CHECKSUM") .fails(); - assert!(result - .stderr_str() - .contains("input: No such file or directory")); - assert!(result - .stderr_str() - .contains("2 lines are improperly formatted\n")); - assert!(result - .stderr_str() - .contains("1 listed file could not be read\n")); + assert!( + result + .stderr_str() + .contains("input: No such file or directory") + ); + assert!( + result + .stderr_str() + .contains("2 lines are improperly formatted\n") + ); + assert!( + result + .stderr_str() + .contains("1 listed file could not be read\n") + ); assert!(result.stdout_str().contains("f: OK\n")); // without strict let result = scene.ucmd().arg("--check").arg("CHECKSUM").fails(); - assert!(result - .stderr_str() - .contains("input: No such file or directory")); - assert!(result - .stderr_str() - .contains("2 lines are improperly formatted\n")); - assert!(result - .stderr_str() - .contains("1 listed file could not be read\n")); + assert!( + result + .stderr_str() + .contains("input: No such file or directory") + ); + assert!( + result + .stderr_str() + .contains("2 lines are improperly formatted\n") + ); + assert!( + result + .stderr_str() + .contains("1 listed file could not be read\n") + ); assert!(result.stdout_str().contains("f: OK\n")); // tests with two files @@ -1010,15 +1022,21 @@ fn test_cksum_check_failed() { .fails(); println!("result.stderr_str() {}", result.stderr_str()); println!("result.stdout_str() {}", result.stdout_str()); - assert!(result - .stderr_str() - .contains("input2: No such file or directory")); - assert!(result - .stderr_str() - .contains("4 lines are improperly formatted\n")); - assert!(result - .stderr_str() - .contains("2 listed files could not be read\n")); + assert!( + result + .stderr_str() + .contains("input2: No such file or directory") + ); + assert!( + result + .stderr_str() + .contains("4 lines are improperly formatted\n") + ); + assert!( + result + .stderr_str() + .contains("2 listed files could not be read\n") + ); assert!(result.stdout_str().contains("f: OK\n")); assert!(result.stdout_str().contains("2: OK\n")); } @@ -1088,9 +1106,11 @@ fn test_cksum_mixed() { println!("result.stderr_str() {}", result.stderr_str()); println!("result.stdout_str() {}", result.stdout_str()); assert!(result.stdout_str().contains("f: OK")); - assert!(result - .stderr_str() - .contains("3 lines are improperly formatted")); + assert!( + result + .stderr_str() + .contains("3 lines are improperly formatted") + ); } #[test] @@ -1221,9 +1241,7 @@ fn test_check_directory_error() { #[test] fn test_check_base64_hashes() { - let hashes = - "MD5 (empty) = 1B2M2Y8AsgTpgAmY7PhCfg==\nSHA256 (empty) = 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=\nBLAKE2b (empty) = eGoC90IBWQPGxv2FJVLScpEvR0DhWEdhiobiF/cfVBnSXhAxr+5YUxOJZESTTrBLkDpoWxRIt1XVb3Aa/pvizg==\n" - ; + let hashes = "MD5 (empty) = 1B2M2Y8AsgTpgAmY7PhCfg==\nSHA256 (empty) = 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=\nBLAKE2b (empty) = eGoC90IBWQPGxv2FJVLScpEvR0DhWEdhiobiF/cfVBnSXhAxr+5YUxOJZESTTrBLkDpoWxRIt1XVb3Aa/pvizg==\n"; let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -1680,11 +1698,11 @@ mod gnu_cksum_base64 { ), ( "sha512", - "z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==" + "z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==", ), ( "blake2b", - "eGoC90IBWQPGxv2FJVLScpEvR0DhWEdhiobiF/cfVBnSXhAxr+5YUxOJZESTTrBLkDpoWxRIt1XVb3Aa/pvizg==" + "eGoC90IBWQPGxv2FJVLScpEvR0DhWEdhiobiF/cfVBnSXhAxr+5YUxOJZESTTrBLkDpoWxRIt1XVb3Aa/pvizg==", ), ("sm3", "GrIdg1XPoX+OYRlIMegajyK+yMco/vt0ftA161CCqis="), ]; diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 17a0372bf..d7af5faed 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -1337,13 +1337,15 @@ fn test_cp_deref() { .join(TEST_COPY_TO_FOLDER) .join(TEST_HELLO_WORLD_SOURCE_SYMLINK); // unlike -P/--no-deref, we expect a file, not a link - assert!(at.file_exists( - path_to_new_symlink - .clone() - .into_os_string() - .into_string() - .unwrap() - )); + assert!( + at.file_exists( + path_to_new_symlink + .clone() + .into_os_string() + .into_string() + .unwrap() + ) + ); // Check the content of the destination file that was copied. assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); let path_to_check = path_to_new_symlink.to_str().unwrap(); @@ -1374,13 +1376,15 @@ fn test_cp_no_deref() { .subdir .join(TEST_COPY_TO_FOLDER) .join(TEST_HELLO_WORLD_SOURCE_SYMLINK); - assert!(at.is_symlink( - &path_to_new_symlink - .clone() - .into_os_string() - .into_string() - .unwrap() - )); + assert!( + at.is_symlink( + &path_to_new_symlink + .clone() + .into_os_string() + .into_string() + .unwrap() + ) + ); // Check the content of the destination file that was copied. assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); let path_to_check = path_to_new_symlink.to_str().unwrap(); @@ -1421,14 +1425,16 @@ fn test_cp_no_deref_link_onto_link() { .succeeds(); // Ensure that the target of the destination was not modified. - assert!(!at - .symlink_metadata(TEST_HELLO_WORLD_DEST) - .file_type() - .is_symlink()); - assert!(at - .symlink_metadata(TEST_HELLO_WORLD_DEST_SYMLINK) - .file_type() - .is_symlink()); + assert!( + !at.symlink_metadata(TEST_HELLO_WORLD_DEST) + .file_type() + .is_symlink() + ); + assert!( + at.symlink_metadata(TEST_HELLO_WORLD_DEST_SYMLINK) + .file_type() + .is_symlink() + ); assert_eq!(at.read(TEST_HELLO_WORLD_DEST_SYMLINK), "Hello, World!\n"); } @@ -2060,13 +2066,15 @@ fn test_cp_deref_folder_to_folder() { .subdir .join(TEST_COPY_TO_FOLDER_NEW) .join(TEST_HELLO_WORLD_SOURCE_SYMLINK); - assert!(at.file_exists( - path_to_new_symlink - .clone() - .into_os_string() - .into_string() - .unwrap() - )); + assert!( + at.file_exists( + path_to_new_symlink + .clone() + .into_os_string() + .into_string() + .unwrap() + ) + ); let path_to_new = at.subdir.join(TEST_COPY_TO_FOLDER_NEW_FILE); @@ -2156,13 +2164,15 @@ fn test_cp_no_deref_folder_to_folder() { .subdir .join(TEST_COPY_TO_FOLDER_NEW) .join(TEST_HELLO_WORLD_SOURCE_SYMLINK); - assert!(at.is_symlink( - &path_to_new_symlink - .clone() - .into_os_string() - .into_string() - .unwrap() - )); + assert!( + at.is_symlink( + &path_to_new_symlink + .clone() + .into_os_string() + .into_string() + .unwrap() + ) + ); let path_to_new = at.subdir.join(TEST_COPY_TO_FOLDER_NEW_FILE); @@ -2254,18 +2264,22 @@ fn test_cp_archive_recursive() { assert!(at.file_exists(at.subdir.join(TEST_COPY_TO_FOLDER_NEW).join("1"))); assert!(at.file_exists(at.subdir.join(TEST_COPY_TO_FOLDER_NEW).join("2"))); - assert!(at.is_symlink( - &at.subdir - .join(TEST_COPY_TO_FOLDER_NEW) - .join("1.link") - .to_string_lossy() - )); - assert!(at.is_symlink( - &at.subdir - .join(TEST_COPY_TO_FOLDER_NEW) - .join("2.link") - .to_string_lossy() - )); + assert!( + at.is_symlink( + &at.subdir + .join(TEST_COPY_TO_FOLDER_NEW) + .join("1.link") + .to_string_lossy() + ) + ); + assert!( + at.is_symlink( + &at.subdir + .join(TEST_COPY_TO_FOLDER_NEW) + .join("2.link") + .to_string_lossy() + ) + ); } #[test] @@ -3974,13 +3988,17 @@ fn test_cp_seen_file() { let result = ts.ucmd().arg("a/f").arg("b/f").arg("c").fails(); #[cfg(not(unix))] - assert!(result - .stderr_str() - .contains("will not overwrite just-created 'c\\f' with 'b/f'")); + assert!( + result + .stderr_str() + .contains("will not overwrite just-created 'c\\f' with 'b/f'") + ); #[cfg(unix)] - assert!(result - .stderr_str() - .contains("will not overwrite just-created 'c/f' with 'b/f'")); + assert!( + result + .stderr_str() + .contains("will not overwrite just-created 'c/f' with 'b/f'") + ); assert!(at.plus("c").join("f").exists()); @@ -6073,11 +6091,13 @@ fn test_cp_preserve_xattr_readonly_source() { ); at.set_readonly(source_file); - assert!(scene - .fixtures - .metadata(source_file) - .permissions() - .readonly()); + assert!( + scene + .fixtures + .metadata(source_file) + .permissions() + .readonly() + ); scene .ucmd() diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index 86b2e0439..4e7c543fc 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -266,9 +266,11 @@ fn test_date_set_mac_unavailable() { .arg("2020-03-11 21:45:00+08:00") .fails(); result.no_stdout(); - assert!(result - .stderr_str() - .starts_with("date: setting the date is not supported by macOS")); + assert!( + result + .stderr_str() + .starts_with("date: setting the date is not supported by macOS") + ); } #[test] diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index 792b88294..70aebf6f4 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -4,11 +4,11 @@ // file that was distributed with this source code. // spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, availible, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat abcdefghijklm abcdefghi nabcde nabcdefg abcdefg fifoname seekable +use crate::common::util::TestScenario; #[cfg(all(unix, not(feature = "feat_selinux")))] use crate::common::util::run_ucmd_as_root_with_stdin_stdout; -use crate::common::util::TestScenario; #[cfg(all(not(windows), feature = "printf"))] -use crate::common::util::{UCommand, TESTS_BINARY}; +use crate::common::util::{TESTS_BINARY, UCommand}; use regex::Regex; use uucore::io::OwnedFileDescriptorOrHandle; @@ -30,21 +30,15 @@ use std::time::Duration; use tempfile::tempfile; macro_rules! inf { - ($fname:expr) => {{ - &format!("if={}", $fname) - }}; + ($fname:expr) => {{ &format!("if={}", $fname) }}; } macro_rules! of { - ($fname:expr) => {{ - &format!("of={}", $fname) - }}; + ($fname:expr) => {{ &format!("of={}", $fname) }}; } macro_rules! fixture_path { - ($fname:expr) => {{ - PathBuf::from(format!("./tests/fixtures/dd/{}", $fname)) - }}; + ($fname:expr) => {{ PathBuf::from(format!("./tests/fixtures/dd/{}", $fname)) }}; } macro_rules! assert_fixture_exists { diff --git a/tests/by-util/test_dircolors.rs b/tests/by-util/test_dircolors.rs index e5fba5eb5..6665d3bc7 100644 --- a/tests/by-util/test_dircolors.rs +++ b/tests/by-util/test_dircolors.rs @@ -5,7 +5,7 @@ // spell-checker:ignore overridable colorterm use crate::common::util::TestScenario; -use dircolors::{guess_syntax, OutputFmt, StrUtils}; +use dircolors::{OutputFmt, StrUtils, guess_syntax}; #[test] fn test_invalid_arg() { diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index 468f2d81d..c205923ff 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -7,9 +7,9 @@ #[cfg(not(windows))] use regex::Regex; +use crate::common::util::TestScenario; #[cfg(not(target_os = "windows"))] use crate::common::util::expected_result; -use crate::common::util::TestScenario; #[cfg(not(target_os = "openbsd"))] const SUB_DIR: &str = "subdir/deeper"; diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 1b8974a90..c52c540e0 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -1013,7 +1013,7 @@ mod tests_split_iterator { use std::ffi::OsString; - use env::native_int_str::{from_native_int_representation_owned, Convert, NCvt}; + use env::native_int_str::{Convert, NCvt, from_native_int_representation_owned}; use env::parse_error::ParseError; fn split(input: &str) -> Result, ParseError> { @@ -1250,8 +1250,8 @@ mod test_raw_string_parser { use env::{ native_int_str::{ - from_native_int_representation, from_native_int_representation_owned, - to_native_int_representation, NativeStr, + NativeStr, from_native_int_representation, from_native_int_representation_owned, + to_native_int_representation, }, string_expander::StringExpander, string_parser, diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index 4d365a343..4e784b701 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -15,7 +15,7 @@ use crate::common::util::TestScenario; use std::time::{Duration, SystemTime}; use rand::distr::{Distribution, Uniform}; -use rand::{rngs::SmallRng, Rng, SeedableRng}; +use rand::{Rng, SeedableRng, rngs::SmallRng}; const NUM_PRIMES: usize = 10000; const NUM_TESTS: usize = 100; diff --git a/tests/by-util/test_groups.rs b/tests/by-util/test_groups.rs index b562f62fa..848b81621 100644 --- a/tests/by-util/test_groups.rs +++ b/tests/by-util/test_groups.rs @@ -5,7 +5,7 @@ //spell-checker: ignore coreutil -use crate::common::util::{check_coreutil_version, expected_result, whoami, TestScenario}; +use crate::common::util::{TestScenario, check_coreutil_version, expected_result, whoami}; const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31 diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index 2e6b3f45f..f4c320ef9 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -1009,14 +1009,15 @@ fn test_sha256_binary() { let ts = TestScenario::new(util_name!()); assert_eq!( ts.fixtures.read("binary.sha256.expected"), - get_hash!(ts - .ucmd() - .arg("--sha256") - .arg("--bits=256") - .arg("binary.png") - .succeeds() - .no_stderr() - .stdout_str()) + get_hash!( + ts.ucmd() + .arg("--sha256") + .arg("--bits=256") + .arg("binary.png") + .succeeds() + .no_stderr() + .stdout_str() + ) ); } @@ -1025,14 +1026,15 @@ fn test_sha256_stdin_binary() { let ts = TestScenario::new(util_name!()); assert_eq!( ts.fixtures.read("binary.sha256.expected"), - get_hash!(ts - .ucmd() - .arg("--sha256") - .arg("--bits=256") - .pipe_in_fixture("binary.png") - .succeeds() - .no_stderr() - .stdout_str()) + get_hash!( + ts.ucmd() + .arg("--sha256") + .arg("--bits=256") + .pipe_in_fixture("binary.png") + .succeeds() + .no_stderr() + .stdout_str() + ) ); } diff --git a/tests/by-util/test_id.rs b/tests/by-util/test_id.rs index e3a7c379f..71707804f 100644 --- a/tests/by-util/test_id.rs +++ b/tests/by-util/test_id.rs @@ -5,7 +5,7 @@ // spell-checker:ignore (ToDO) coreutil -use crate::common::util::{check_coreutil_version, expected_result, is_ci, whoami, TestScenario}; +use crate::common::util::{TestScenario, check_coreutil_version, expected_result, is_ci, whoami}; const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31 diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index cbeeaa942..6d8ba774b 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore (words) helloworld nodir objdump n'source -use crate::common::util::{is_ci, run_ucmd_as_root, TestScenario}; +use crate::common::util::{TestScenario, is_ci, run_ucmd_as_root}; #[cfg(not(target_os = "openbsd"))] use filetime::FileTime; use std::fs; diff --git a/tests/by-util/test_ln.rs b/tests/by-util/test_ln.rs index 5303c8173..57e793dd2 100644 --- a/tests/by-util/test_ln.rs +++ b/tests/by-util/test_ln.rs @@ -337,11 +337,13 @@ fn test_symlink_overwrite_dir_fail() { at.touch(path_a); at.mkdir(path_b); - assert!(!ucmd - .args(&["-s", "-T", path_a, path_b]) - .fails() - .stderr_str() - .is_empty()); + assert!( + !ucmd + .args(&["-s", "-T", path_a, path_b]) + .fails() + .stderr_str() + .is_empty() + ); } #[test] @@ -391,11 +393,13 @@ fn test_symlink_target_only() { at.mkdir(dir); - assert!(!ucmd - .args(&["-s", "-t", dir]) - .fails() - .stderr_str() - .is_empty()); + assert!( + !ucmd + .args(&["-s", "-t", dir]) + .fails() + .stderr_str() + .is_empty() + ); } #[test] @@ -797,13 +801,17 @@ fn test_ln_seen_file() { let result = ts.ucmd().arg("a/f").arg("b/f").arg("c").fails(); #[cfg(not(unix))] - assert!(result - .stderr_str() - .contains("will not overwrite just-created 'c\\f' with 'b/f'")); + assert!( + result + .stderr_str() + .contains("will not overwrite just-created 'c\\f' with 'b/f'") + ); #[cfg(unix)] - assert!(result - .stderr_str() - .contains("will not overwrite just-created 'c/f' with 'b/f'")); + assert!( + result + .stderr_str() + .contains("will not overwrite just-created 'c/f' with 'b/f'") + ); assert!(at.plus("c").join("f").exists()); // b/f still exists diff --git a/tests/by-util/test_logname.rs b/tests/by-util/test_logname.rs index 4fafd243b..178b47048 100644 --- a/tests/by-util/test_logname.rs +++ b/tests/by-util/test_logname.rs @@ -2,7 +2,7 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::common::util::{is_ci, TestScenario}; +use crate::common::util::{TestScenario, is_ci}; use std::env; #[test] diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 6b9be8eb5..444d5b8d8 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -10,9 +10,9 @@ clippy::cast_possible_truncation )] +use crate::common::util::TestScenario; #[cfg(any(unix, feature = "feat_selinux"))] use crate::common::util::expected_result; -use crate::common::util::TestScenario; #[cfg(all(unix, feature = "chmod"))] use nix::unistd::{close, dup}; use regex::Regex; @@ -1033,9 +1033,10 @@ fn test_ls_zero() { ); let result = scene.ucmd().args(&["--zero", "--color=always"]).succeeds(); - assert_eq!(result.stdout_str(), - "\u{1b}[0m\u{1b}[01;34m0-test-zero\x1b[0m\x001\ntest-zero\x002-test-zero\x003-test-zero\x00", - ); + assert_eq!( + result.stdout_str(), + "\u{1b}[0m\u{1b}[01;34m0-test-zero\x1b[0m\x001\ntest-zero\x002-test-zero\x003-test-zero\x00", + ); scene .ucmd() @@ -5029,15 +5030,19 @@ fn test_ls_hyperlink() { let result = scene.ucmd().arg("--hyperlink").succeeds(); assert!(result.stdout_str().contains("\x1b]8;;file://")); - assert!(result - .stdout_str() - .contains(&format!("{path}{separator}{file}\x07{file}\x1b]8;;\x07"))); + assert!( + result + .stdout_str() + .contains(&format!("{path}{separator}{file}\x07{file}\x1b]8;;\x07")) + ); let result = scene.ucmd().arg("--hyperlink=always").succeeds(); assert!(result.stdout_str().contains("\x1b]8;;file://")); - assert!(result - .stdout_str() - .contains(&format!("{path}{separator}{file}\x07{file}\x1b]8;;\x07"))); + assert!( + result + .stdout_str() + .contains(&format!("{path}{separator}{file}\x07{file}\x1b]8;;\x07")) + ); for argument in [ "--hyperlink=never", @@ -5069,19 +5074,27 @@ fn test_ls_hyperlink_encode_link() { let result = ucmd.arg("--hyperlink").succeeds(); #[cfg(not(target_os = "windows"))] { - assert!(result - .stdout_str() - .contains("back%5cslash\x07back\\slash\x1b]8;;\x07")); - assert!(result - .stdout_str() - .contains("ques%3ftion\x07ques?tion\x1b]8;;\x07")); + assert!( + result + .stdout_str() + .contains("back%5cslash\x07back\\slash\x1b]8;;\x07") + ); + assert!( + result + .stdout_str() + .contains("ques%3ftion\x07ques?tion\x1b]8;;\x07") + ); } - assert!(result - .stdout_str() - .contains("encoded%253Fquestion\x07encoded%3Fquestion\x1b]8;;\x07")); - assert!(result - .stdout_str() - .contains("sp%20ace\x07sp ace\x1b]8;;\x07")); + assert!( + result + .stdout_str() + .contains("encoded%253Fquestion\x07encoded%3Fquestion\x1b]8;;\x07") + ); + assert!( + result + .stdout_str() + .contains("sp%20ace\x07sp ace\x1b]8;;\x07") + ); } // spell-checker: enable @@ -5106,19 +5119,23 @@ fn test_ls_hyperlink_dirs() { .succeeds(); assert!(result.stdout_str().contains("\x1b]8;;file://")); - assert!(result - .stdout_str() - .lines() - .next() - .unwrap() - .contains(&format!("{path}{separator}{dir_a}\x07{dir_a}\x1b]8;;\x07:"))); + assert!( + result + .stdout_str() + .lines() + .next() + .unwrap() + .contains(&format!("{path}{separator}{dir_a}\x07{dir_a}\x1b]8;;\x07:")) + ); assert_eq!(result.stdout_str().lines().nth(1).unwrap(), ""); - assert!(result - .stdout_str() - .lines() - .nth(2) - .unwrap() - .contains(&format!("{path}{separator}{dir_b}\x07{dir_b}\x1b]8;;\x07:"))); + assert!( + result + .stdout_str() + .lines() + .nth(2) + .unwrap() + .contains(&format!("{path}{separator}{dir_b}\x07{dir_b}\x1b]8;;\x07:")) + ); } #[test] diff --git a/tests/by-util/test_mknod.rs b/tests/by-util/test_mknod.rs index ffd97a5fc..e0a091778 100644 --- a/tests/by-util/test_mknod.rs +++ b/tests/by-util/test_mknod.rs @@ -23,12 +23,14 @@ fn test_mknod_help() { #[test] #[cfg(not(windows))] fn test_mknod_version() { - assert!(new_ucmd!() - .arg("--version") - .succeeds() - .no_stderr() - .stdout_str() - .starts_with("mknod")); + assert!( + new_ucmd!() + .arg("--version") + .succeeds() + .no_stderr() + .stdout_str() + .starts_with("mknod") + ); } #[test] diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index 033499c79..c35ddf31b 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -8,9 +8,9 @@ use crate::common::util::TestScenario; use uucore::display::Quotable; -use std::path::PathBuf; #[cfg(not(windows))] use std::path::MAIN_SEPARATOR; +use std::path::PathBuf; use tempfile::tempdir; #[cfg(unix)] diff --git a/tests/by-util/test_more.rs b/tests/by-util/test_more.rs index 3941dc1da..3c40c8fd9 100644 --- a/tests/by-util/test_more.rs +++ b/tests/by-util/test_more.rs @@ -112,7 +112,7 @@ fn test_more_dir_arg() { #[test] #[cfg(target_family = "unix")] fn test_more_invalid_file_perms() { - use std::fs::{set_permissions, Permissions}; + use std::fs::{Permissions, set_permissions}; use std::os::unix::fs::PermissionsExt; if std::io::stdout().is_terminal() { diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 6dcb409f8..e9bed3949 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -1377,13 +1377,15 @@ fn test_mv_errors() { // $ at.mkdir dir && at.touch file // $ mv dir file // err == mv: cannot overwrite non-directory 'file' with directory 'dir' - assert!(!scene - .ucmd() - .arg(dir) - .arg(file_a) - .fails() - .stderr_str() - .is_empty()); + assert!( + !scene + .ucmd() + .arg(dir) + .arg(file_a) + .fails() + .stderr_str() + .is_empty() + ); } #[test] @@ -1448,15 +1450,17 @@ fn test_mv_interactive_error() { // $ at.mkdir dir && at.touch file // $ mv -i dir file // err == mv: cannot overwrite non-directory 'file' with directory 'dir' - assert!(!scene - .ucmd() - .arg("-i") - .arg(dir) - .arg(file_a) - .pipe_in("y") - .fails() - .stderr_str() - .is_empty()); + assert!( + !scene + .ucmd() + .arg("-i") + .arg(dir) + .arg(file_a) + .pipe_in("y") + .fails() + .stderr_str() + .is_empty() + ); } #[test] @@ -1581,13 +1585,17 @@ fn test_mv_seen_file() { let result = ts.ucmd().arg("a/f").arg("b/f").arg("c").fails(); #[cfg(not(unix))] - assert!(result - .stderr_str() - .contains("will not overwrite just-created 'c\\f' with 'b/f'")); + assert!( + result + .stderr_str() + .contains("will not overwrite just-created 'c\\f' with 'b/f'") + ); #[cfg(unix)] - assert!(result - .stderr_str() - .contains("will not overwrite just-created 'c/f' with 'b/f'")); + assert!( + result + .stderr_str() + .contains("will not overwrite just-created 'c/f' with 'b/f'") + ); // a/f has been moved into c/f assert!(at.plus("c").join("f").exists()); @@ -1611,13 +1619,17 @@ fn test_mv_seen_multiple_files_to_directory() { let result = ts.ucmd().arg("a/f").arg("b/f").arg("b/g").arg("c").fails(); #[cfg(not(unix))] - assert!(result - .stderr_str() - .contains("will not overwrite just-created 'c\\f' with 'b/f'")); + assert!( + result + .stderr_str() + .contains("will not overwrite just-created 'c\\f' with 'b/f'") + ); #[cfg(unix)] - assert!(result - .stderr_str() - .contains("will not overwrite just-created 'c/f' with 'b/f'")); + assert!( + result + .stderr_str() + .contains("will not overwrite just-created 'c/f' with 'b/f'") + ); assert!(!at.plus("a").join("f").exists()); assert!(at.plus("b").join("f").exists()); @@ -1756,7 +1768,7 @@ fn test_move_should_not_fallback_to_copy() { mod inter_partition_copying { use crate::common::util::TestScenario; use std::fs::{read_to_string, set_permissions, write}; - use std::os::unix::fs::{symlink, PermissionsExt}; + use std::os::unix::fs::{PermissionsExt, symlink}; use tempfile::TempDir; // Ensure that the copying code used in an inter-partition move unlinks the destination symlink. diff --git a/tests/by-util/test_nice.rs b/tests/by-util/test_nice.rs index 177ab9478..eb82c3bd6 100644 --- a/tests/by-util/test_nice.rs +++ b/tests/by-util/test_nice.rs @@ -24,9 +24,10 @@ fn test_negative_adjustment() { // correctly. let res = new_ucmd!().args(&["-n", "-1", "true"]).succeeds(); - assert!(res - .stderr_str() - .starts_with("nice: warning: setpriority: Permission denied")); // spell-checker:disable-line + assert!( + res.stderr_str() + .starts_with("nice: warning: setpriority: Permission denied") + ); // spell-checker:disable-line } #[test] diff --git a/tests/by-util/test_pinky.rs b/tests/by-util/test_pinky.rs index be04e8a68..6192a7bb5 100644 --- a/tests/by-util/test_pinky.rs +++ b/tests/by-util/test_pinky.rs @@ -6,7 +6,7 @@ #[cfg(target_os = "openbsd")] use crate::common::util::TestScenario; #[cfg(not(target_os = "openbsd"))] -use crate::common::util::{expected_result, TestScenario}; +use crate::common::util::{TestScenario, expected_result}; use pinky::Capitalize; #[cfg(not(target_os = "openbsd"))] use uucore::entries::{Locate, Passwd}; diff --git a/tests/by-util/test_readlink.rs b/tests/by-util/test_readlink.rs index 14dd4a557..eef42eeeb 100644 --- a/tests/by-util/test_readlink.rs +++ b/tests/by-util/test_readlink.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // spell-checker:ignore regfile -use crate::common::util::{get_root_path, TestScenario}; +use crate::common::util::{TestScenario, get_root_path}; static GIBBERISH: &str = "supercalifragilisticexpialidocious"; diff --git a/tests/by-util/test_realpath.rs b/tests/by-util/test_realpath.rs index cf6ea5b4a..14c2aa881 100644 --- a/tests/by-util/test_realpath.rs +++ b/tests/by-util/test_realpath.rs @@ -3,11 +3,11 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. // spell-checker:ignore nusr -use crate::common::util::{get_root_path, TestScenario}; +use crate::common::util::{TestScenario, get_root_path}; #[cfg(windows)] use regex::Regex; -use std::path::{Path, MAIN_SEPARATOR}; +use std::path::{MAIN_SEPARATOR, Path}; static GIBBERISH: &str = "supercalifragilisticexpialidocious"; diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 494505715..a12f8d580 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -5,7 +5,7 @@ // spell-checker:ignore xzaaa sixhundredfiftyonebytes ninetyonebytes threebytes asciilowercase ghijkl mnopq rstuv wxyz fivelines twohundredfortyonebytes onehundredlines nbbbb dxen ncccc rlimit NOFILE use crate::common::util::{AtPath, TestScenario}; -use rand::{rng, Rng, SeedableRng}; +use rand::{Rng, SeedableRng, rng}; use regex::Regex; #[cfg(any(target_os = "linux", target_os = "android"))] use rlimit::Resource; @@ -13,7 +13,7 @@ use rlimit::Resource; use std::env; use std::path::Path; use std::{ - fs::{read_dir, File}, + fs::{File, read_dir}, io::{BufWriter, Read, Write}, }; diff --git a/tests/by-util/test_stat.rs b/tests/by-util/test_stat.rs index 998bb3002..a0835c8f2 100644 --- a/tests/by-util/test_stat.rs +++ b/tests/by-util/test_stat.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::common::util::{expected_result, TestScenario}; +use crate::common::util::{TestScenario, expected_result}; #[test] fn test_invalid_arg() { diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index aba0109ee..c4da1de6d 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -14,11 +14,11 @@ )] use crate::common::random::{AlphanumericNewline, RandomizedString}; +use crate::common::util::TestScenario; #[cfg(unix)] use crate::common::util::expected_result; #[cfg(not(windows))] use crate::common::util::is_ci; -use crate::common::util::TestScenario; use pretty_assertions::assert_eq; use rand::distr::Alphanumeric; use rstest::rstest; diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index bfd9bacac..e4e24acb4 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -274,8 +274,10 @@ mod linux_only { name, contents.len() ); - assert!(contents.starts_with(&compare), - "Expected truncated output to be a prefix of the correct output, but it isn't.\n Correct: {contents}\n Compare: {compare}"); + assert!( + contents.starts_with(&compare), + "Expected truncated output to be a prefix of the correct output, but it isn't.\n Correct: {contents}\n Compare: {compare}" + ); } #[test] diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index c4b27c8b7..120159672 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -5,9 +5,9 @@ // spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime use crate::common::util::{AtPath, TestScenario}; +use filetime::FileTime; #[cfg(not(target_os = "freebsd"))] use filetime::set_symlink_file_times; -use filetime::FileTime; use std::fs::remove_file; use std::path::PathBuf; diff --git a/tests/by-util/test_wc.rs b/tests/by-util/test_wc.rs index e25f2a091..a48b05581 100644 --- a/tests/by-util/test_wc.rs +++ b/tests/by-util/test_wc.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::common::util::{vec_of_size, TestScenario}; +use crate::common::util::{TestScenario, vec_of_size}; // spell-checker:ignore (flags) lwmcL clmwL ; (path) bogusfile emptyfile manyemptylines moby notrailingnewline onelongemptyline onelongword weirdchars #[test] diff --git a/tests/by-util/test_who.rs b/tests/by-util/test_who.rs index 21d51f93d..252c26ec1 100644 --- a/tests/by-util/test_who.rs +++ b/tests/by-util/test_who.rs @@ -5,7 +5,7 @@ // spell-checker:ignore (flags) runlevel mesg -use crate::common::util::{expected_result, TestScenario}; +use crate::common::util::{TestScenario, expected_result}; #[test] fn test_invalid_arg() { diff --git a/tests/by-util/test_whoami.rs b/tests/by-util/test_whoami.rs index 1d685fe98..bc0a9908c 100644 --- a/tests/by-util/test_whoami.rs +++ b/tests/by-util/test_whoami.rs @@ -5,7 +5,7 @@ #[cfg(unix)] use crate::common::util::expected_result; -use crate::common::util::{is_ci, whoami, TestScenario}; +use crate::common::util::{TestScenario, is_ci, whoami}; #[test] fn test_invalid_arg() { diff --git a/tests/common/random.rs b/tests/common/random.rs index 9f285fb6c..7a13f1e1d 100644 --- a/tests/common/random.rs +++ b/tests/common/random.rs @@ -5,7 +5,7 @@ #![allow(clippy::naive_bytecount)] use rand::distr::{Distribution, Uniform}; -use rand::{rng, Rng}; +use rand::{Rng, rng}; /// Samples alphanumeric characters `[A-Za-z0-9]` including newline `\n` /// diff --git a/tests/common/util.rs b/tests/common/util.rs index 1a4717170..4b7acaa54 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -29,12 +29,12 @@ use std::collections::VecDeque; #[cfg(not(windows))] use std::ffi::CString; use std::ffi::{OsStr, OsString}; -use std::fs::{self, hard_link, remove_file, File, OpenOptions}; +use std::fs::{self, File, OpenOptions, hard_link, remove_file}; use std::io::{self, BufWriter, Read, Result, Write}; #[cfg(unix)] use std::os::fd::OwnedFd; #[cfg(unix)] -use std::os::unix::fs::{symlink as symlink_dir, symlink as symlink_file, PermissionsExt}; +use std::os::unix::fs::{PermissionsExt, symlink as symlink_dir, symlink as symlink_file}; #[cfg(unix)] use std::os::unix::process::CommandExt; #[cfg(unix)] @@ -47,7 +47,7 @@ use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::rc::Rc; use std::sync::mpsc::{self, RecvTimeoutError}; -use std::thread::{sleep, JoinHandle}; +use std::thread::{JoinHandle, sleep}; use std::time::{Duration, Instant}; use std::{env, hint, mem, thread}; use tempfile::{Builder, TempDir}; @@ -506,7 +506,9 @@ impl CmdResult { /// whose bytes equal those of the passed in slice #[track_caller] pub fn stdout_is_bytes>(&self, msg: T) -> &Self { - assert_eq!(self.stdout, msg.as_ref(), + assert_eq!( + self.stdout, + msg.as_ref(), "stdout as bytes wasn't equal to expected bytes. Result as strings:\nstdout ='{:?}'\nexpected='{:?}'", std::str::from_utf8(&self.stdout), std::str::from_utf8(msg.as_ref()), @@ -780,11 +782,7 @@ pub fn recursive_copy(src: &Path, dest: &Path) -> Result<()> { } pub fn get_root_path() -> &'static str { - if cfg!(windows) { - "C:\\" - } else { - "/" - } + if cfg!(windows) { "C:\\" } else { "/" } } /// Compares the extended attributes (xattrs) of two files or directories. @@ -1874,10 +1872,11 @@ impl UCommand { impl std::fmt::Display for UCommand { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut comm_string: Vec = vec![self - .bin_path - .as_ref() - .map_or(String::new(), |p| p.display().to_string())]; + let mut comm_string: Vec = vec![ + self.bin_path + .as_ref() + .map_or(String::new(), |p| p.display().to_string()), + ]; comm_string.extend(self.args.iter().map(|s| s.to_string_lossy().to_string())); f.write_str(&comm_string.join(" ")) } @@ -2062,11 +2061,7 @@ impl<'a> UChildAssertion<'a> { // Assert that the child process is alive #[track_caller] pub fn is_alive(&mut self) -> &mut Self { - match self - .uchild - .raw - .try_wait() - { + match self.uchild.raw.try_wait() { Ok(Some(status)) => panic!( "Assertion failed. Expected '{}' to be running but exited with status={}.\nstdout: {}\nstderr: {}", uucore::util_name(), @@ -2084,17 +2079,14 @@ impl<'a> UChildAssertion<'a> { // Assert that the child process has exited #[track_caller] pub fn is_not_alive(&mut self) -> &mut Self { - match self - .uchild - .raw - .try_wait() - { + match self.uchild.raw.try_wait() { Ok(None) => panic!( "Assertion failed. Expected '{}' to be not running but was alive.\nstdout: {}\nstderr: {}", uucore::util_name(), self.uchild.stdout_all(), - self.uchild.stderr_all()), - Ok(_) => {}, + self.uchild.stderr_all() + ), + Ok(_) => {} Err(error) => panic!("Assertion failed with error '{error:?}'"), } @@ -4051,11 +4043,7 @@ mod tests { // make sure we are not testing against the same umask let c_umask = if p_umask == 0o002 { 0o007 } else { 0o002 }; let expected = if cfg!(target_os = "android") { - if p_umask == 0o002 { - "007\n" - } else { - "002\n" - } + if p_umask == 0o002 { "007\n" } else { "002\n" } } else if p_umask == 0o002 { "0007\n" } else { diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index 2af85d42e..dd8cd9359 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -23,9 +23,11 @@ fn execution_phrase_double() { .arg("--some-invalid-arg") .output() .unwrap(); - assert!(String::from_utf8(output.stderr) - .unwrap() - .contains(&format!("Usage: {} ls", scenario.bin_path.display(),))); + assert!( + String::from_utf8(output.stderr) + .unwrap() + .contains(&format!("Usage: {} ls", scenario.bin_path.display(),)) + ); } #[test]