From 3c14f72bf661b78639f60acd71fdbeb5fe952515 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Wed, 21 Oct 2026 21:43:51 +0100 Subject: [PATCH] refactor(uucore): reformat imports Run `rustfmt` with `imports_granularity = "Module"` to group imports by module. --- src/uucore/src/lib/features/backup_control.rs | 21 ++--- src/uucore/src/lib/features/buf_copy.rs | 10 +-- src/uucore/src/lib/features/entries.rs | 8 +- .../src/lib/features/extendedbigdecimal.rs | 7 +- src/uucore/src/lib/features/fast_inc.rs | 3 +- .../src/lib/features/format/argument.rs | 17 ++--- src/uucore/src/lib/features/format/mod.rs | 22 +++--- .../src/lib/features/format/num_format.rs | 15 ++-- src/uucore/src/lib/features/format/spec.rs | 16 ++-- src/uucore/src/lib/features/fs.rs | 9 +-- src/uucore/src/lib/features/fsext/mod.rs | 6 +- src/uucore/src/lib/features/fsext/windows.rs | 3 +- src/uucore/src/lib/features/i18n/collator.rs | 3 +- src/uucore/src/lib/features/i18n/datetime.rs | 3 +- src/uucore/src/lib/features/mode.rs | 3 +- .../src/lib/features/parser/num_parser.rs | 10 +-- .../src/lib/features/parser/parse_time.rs | 12 +-- .../features/parser/shortcut_value_parser.rs | 10 +-- src/uucore/src/lib/features/perms.rs | 3 +- src/uucore/src/lib/features/pipes.rs | 8 +- src/uucore/src/lib/features/proc_info.rs | 15 ++-- .../src/lib/features/quoting_style/mod.rs | 6 +- src/uucore/src/lib/features/safe_traversal.rs | 6 +- src/uucore/src/lib/features/signals.rs | 6 +- src/uucore/src/lib/features/sum.rs | 4 +- src/uucore/src/lib/features/tty.rs | 6 +- src/uucore/src/lib/features/uptime/unix.rs | 6 +- src/uucore/src/lib/features/utmpx.rs | 76 ++++++------------- src/uucore/src/lib/lib.rs | 18 ++--- src/uucore/src/lib/mods/clap_localization.rs | 3 +- src/uucore/src/lib/mods/display.rs | 3 +- src/uucore/src/lib/mods/error.rs | 12 ++- src/uucore/src/lib/mods/io.rs | 10 +-- src/uucore/src/lib/mods/locale.rs | 6 +- 34 files changed, 136 insertions(+), 230 deletions(-) diff --git a/src/uucore/src/lib/features/backup_control.rs b/src/uucore/src/lib/features/backup_control.rs index 9fb668f3238..bdd9721e672 100644 --- a/src/uucore/src/lib/features/backup_control.rs +++ b/src/uucore/src/lib/features/backup_control.rs @@ -82,20 +82,15 @@ //! } //! ``` -use crate::{ - display::Quotable, - error::{UError, UResult}, - fs::FileInformation, -}; +use crate::display::Quotable; +use crate::error::{UError, UResult}; +use crate::fs::FileInformation; use clap::ArgMatches; -use std::{ - env, - error::Error, - ffi::{OsStr, OsString}, - fmt::{Debug, Display}, - fs, - path::{Path, PathBuf}, -}; +use std::error::Error; +use std::ffi::{OsStr, OsString}; +use std::fmt::{Debug, Display}; +use std::path::{Path, PathBuf}; +use std::{env, fs}; pub static BACKUP_CONTROL_VALUES: &[&str] = &[ "simple", "never", "numbered", "t", "existing", "nil", "none", "off", diff --git a/src/uucore/src/lib/features/buf_copy.rs b/src/uucore/src/lib/features/buf_copy.rs index 9b3bc565e9d..fcddba33930 100644 --- a/src/uucore/src/lib/features/buf_copy.rs +++ b/src/uucore/src/lib/features/buf_copy.rs @@ -34,13 +34,9 @@ mod tests { use std::fs::File; use tempfile::tempdir; - use { - std::fs::OpenOptions, - std::{ - io::{Seek, SeekFrom}, - thread, - }, - }; + use std::fs::OpenOptions; + use std::io::{Seek, SeekFrom}; + use std::thread; use std::io::{Read, Write}; diff --git a/src/uucore/src/lib/features/entries.rs b/src/uucore/src/lib/features/entries.rs index bcf6779130f..67317d1621d 100644 --- a/src/uucore/src/lib/features/entries.rs +++ b/src/uucore/src/lib/features/entries.rs @@ -35,14 +35,10 @@ use core::ffi::{CStr, c_char, c_int}; #[cfg(any(target_vendor = "apple", target_os = "freebsd"))] use libc::time_t; -use libc::{getgrgid, getgrnam}; -use libc::{getpwnam, getpwuid, group, passwd}; -use libc::{gid_t, uid_t}; +use libc::{getgrgid, getgrnam, getpwnam, getpwuid, gid_t, group, passwd, uid_t}; use std::ffi::CString; -use std::io::Error as IOError; -use std::io::ErrorKind; -use std::io::Result as IOResult; +use std::io::{Error as IOError, ErrorKind, Result as IOResult}; use std::ptr; use std::sync::Mutex; diff --git a/src/uucore/src/lib/features/extendedbigdecimal.rs b/src/uucore/src/lib/features/extendedbigdecimal.rs index 92aa3805d15..1431867e8e4 100644 --- a/src/uucore/src/lib/features/extendedbigdecimal.rs +++ b/src/uucore/src/lib/features/extendedbigdecimal.rs @@ -24,14 +24,11 @@ //! ``` use std::cmp::Ordering; -use std::ops::Add; -use std::ops::Neg; +use std::ops::{Add, Neg}; use bigdecimal::BigDecimal; use bigdecimal::num_bigint::BigUint; -use num_traits::FromPrimitive; -use num_traits::Signed; -use num_traits::Zero; +use num_traits::{FromPrimitive, Signed, Zero}; #[derive(Debug, Clone)] pub enum ExtendedBigDecimal { diff --git a/src/uucore/src/lib/features/fast_inc.rs b/src/uucore/src/lib/features/fast_inc.rs index 48474344a68..0503380faef 100644 --- a/src/uucore/src/lib/features/fast_inc.rs +++ b/src/uucore/src/lib/features/fast_inc.rs @@ -116,8 +116,7 @@ pub fn fast_inc_one(val: &mut [u8], start: &mut usize, end: usize) { #[cfg(test)] mod tests { - use crate::fast_inc::fast_inc; - use crate::fast_inc::fast_inc_one; + use crate::fast_inc::{fast_inc, fast_inc_one}; #[test] fn test_fast_inc_simple() { diff --git a/src/uucore/src/lib/features/format/argument.rs b/src/uucore/src/lib/features/format/argument.rs index 401d87df1ca..8a3c25007d2 100644 --- a/src/uucore/src/lib/features/format/argument.rs +++ b/src/uucore/src/lib/features/format/argument.rs @@ -4,19 +4,14 @@ // file that was distributed with this source code. use super::ExtendedBigDecimal; +use crate::error::set_exit_code; use crate::format::spec::ArgumentLocation; -use crate::{ - error::set_exit_code, - os_str_as_bytes, - parser::num_parser::{ExtendedParser, ExtendedParserError}, - quoting_style::{QuotingStyle, locale_aware_escape_name}, - show_error, show_warning, -}; +use crate::parser::num_parser::{ExtendedParser, ExtendedParserError}; +use crate::quoting_style::{QuotingStyle, locale_aware_escape_name}; +use crate::{os_str_as_bytes, show_error, show_warning}; use os_display::Quotable; -use std::{ - ffi::{OsStr, OsString}, - num::NonZero, -}; +use std::ffi::{OsStr, OsString}; +use std::num::NonZero; /// An argument for formatting /// diff --git a/src/uucore/src/lib/features/format/mod.rs b/src/uucore/src/lib/features/format/mod.rs index fa88dfe5903..80d16fff53e 100644 --- a/src/uucore/src/lib/features/format/mod.rs +++ b/src/uucore/src/lib/features/format/mod.rs @@ -42,20 +42,16 @@ pub use self::escape::{EscapeSet, EscapedChar, OctalParsing}; use crate::extendedbigdecimal::ExtendedBigDecimal; pub use argument::{FormatArgument, FormatArguments}; -use self::{escape::parse_escape_code, num_format::Formatter}; -use crate::{ - NonUtf8OsStrError, - error::{UError, strip_errno}, - translate, translate_text, -}; +use self::escape::parse_escape_code; +use self::num_format::Formatter; +use crate::error::{UError, strip_errno}; +use crate::{NonUtf8OsStrError, translate, translate_text}; pub use spec::Spec; -use std::{ - error::Error, - fmt::Display, - io::{Write, stdout}, - marker::PhantomData, - ops::{ControlFlow, Range}, -}; +use std::error::Error; +use std::fmt::Display; +use std::io::{Write, stdout}; +use std::marker::PhantomData; +use std::ops::{ControlFlow, Range}; use os_display::Quotable; diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index e7f9314df65..d196a7db01a 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -9,15 +9,12 @@ use bigdecimal::BigDecimal; use bigdecimal::num_bigint::ToBigInt; -use num_traits::Signed; -use num_traits::Zero; +use num_traits::{Signed, Zero}; use std::cmp::min; use std::io::Write; -use super::{ - ExtendedBigDecimal, FormatError, check_precision, - spec::{CanAsterisk, Spec}, -}; +use super::spec::{CanAsterisk, Spec}; +use super::{ExtendedBigDecimal, FormatError, check_precision}; pub trait Formatter { fn fmt(&self, writer: impl Write, x: T) -> std::io::Result<()>; @@ -865,10 +862,8 @@ mod test { use num_traits::FromPrimitive; use std::str::FromStr; - use crate::format::{ - ExtendedBigDecimal, Format, - num_format::{Case, Float, ForceDecimal, UnsignedInt}, - }; + use crate::format::num_format::{Case, Float, ForceDecimal, UnsignedInt}; + use crate::format::{ExtendedBigDecimal, Format}; use super::{Formatter, SignedInt}; diff --git a/src/uucore/src/lib/features/format/spec.rs b/src/uucore/src/lib/features/format/spec.rs index 069d3069ad0..bfd3a54b793 100644 --- a/src/uucore/src/lib/features/format/spec.rs +++ b/src/uucore/src/lib/features/format/spec.rs @@ -5,16 +5,20 @@ // spell-checker:ignore (vars) intmax ptrdiff padlen +use super::num_format::{ + self, Case, FloatVariant, ForceDecimal, Formatter, NumberAlignment, PositiveSign, Prefix, + UnsignedIntVariant, +}; use super::{ EscapeSet, ExtendedBigDecimal, FormatChar, FormatError, OctalParsing, check_precision, - num_format::{ - self, Case, FloatVariant, ForceDecimal, Formatter, NumberAlignment, PositiveSign, Prefix, - UnsignedIntVariant, - }, parse_escape_only, }; -use crate::{format::FormatArguments, os_str_as_bytes, quoting_style::locale_aware_shell_escape}; -use std::{io::Write, num::NonZero, ops::ControlFlow}; +use crate::format::FormatArguments; +use crate::os_str_as_bytes; +use crate::quoting_style::locale_aware_shell_escape; +use std::io::Write; +use std::num::NonZero; +use std::ops::ControlFlow; /// A parsed specification for formatting a value /// diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index c17fa99d21d..036bd02bd88 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -11,13 +11,10 @@ use crate::translate; #[cfg(all(unix, not(target_os = "haiku")))] pub use libc::{major, makedev, minor}; use std::collections::VecDeque; -use std::env; use std::ffi::{OsStr, OsString}; -use std::fs; use std::fs::read_dir; use std::hash::Hash; -use std::io::Stdin; -use std::io::{Error, ErrorKind, Result as IOResult}; +use std::io::{Error, ErrorKind, Result as IOResult, Stdin}; #[cfg(any(unix, target_os = "wasi"))] use std::os::fd::AsFd; #[cfg(unix)] @@ -29,6 +26,7 @@ use std::os::windows::io::AsRawHandle; use std::path::{Component, MAIN_SEPARATOR, Path, PathBuf}; #[cfg(unix)] use std::sync::OnceLock; +use std::{env, fs}; #[cfg(windows)] use windows_sys::Win32::Foundation::MAX_PATH; #[cfg(windows)] @@ -918,9 +916,10 @@ pub fn is_stdin_directory(stdin: &Stdin) -> bool { pub mod sane_blksize { + use std::fs::metadata; #[cfg(unix)] use std::os::unix::fs::MetadataExt; - use std::{fs::metadata, path::Path}; + use std::path::Path; pub const DEFAULT: u64 = 512; pub const MAX: u64 = (u32::MAX / 8 + 1) as u64; diff --git a/src/uucore/src/lib/features/fsext/mod.rs b/src/uucore/src/lib/features/fsext/mod.rs index 58fd00f1c57..e6db2afd222 100644 --- a/src/uucore/src/lib/features/fsext/mod.rs +++ b/src/uucore/src/lib/features/fsext/mod.rs @@ -36,8 +36,10 @@ use core::ffi::CStr; use libc::{ 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)] use std::ffi::CString; +use std::ffi::OsString; #[cfg(unix)] use std::io::Error as IOError; #[cfg(unix)] @@ -45,7 +47,6 @@ use std::mem; use std::time::SystemTime; #[cfg(unix)] use std::time::UNIX_EPOCH; -use std::{borrow::Cow, ffi::OsString}; use std::fs::Metadata; #[cfg(unix)] @@ -187,8 +188,7 @@ impl MountInfo { #[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin"))] fn new(file_name: &str, raw: &[&[u8]]) -> Option { use std::ffi::OsStr; - use std::os::unix::ffi::OsStrExt; - use std::os::unix::ffi::OsStringExt; + use std::os::unix::ffi::{OsStrExt, OsStringExt}; let (dev_name, fs_type, mount_root, mount_dir, mount_option) = match file_name { // spell-checker:ignore (word) noatime diff --git a/src/uucore/src/lib/features/fsext/windows.rs b/src/uucore/src/lib/features/fsext/windows.rs index dd3eb15b077..b1c363819e5 100644 --- a/src/uucore/src/lib/features/fsext/windows.rs +++ b/src/uucore/src/lib/features/fsext/windows.rs @@ -79,9 +79,8 @@ impl FsUsage { /// Safe wrappers around the Win32 calls; every `unsafe` lives here. mod sys { use std::ffi::{OsStr, OsString}; - use std::io; use std::os::windows::ffi::OsStringExt; - use std::ptr; + use std::{io, ptr}; use crate::wide::{FromWide, ToWide}; use windows_sys::Win32::Foundation::{ diff --git a/src/uucore/src/lib/features/i18n/collator.rs b/src/uucore/src/lib/features/i18n/collator.rs index 51e802ddf5f..7acec13cfbd 100644 --- a/src/uucore/src/lib/features/i18n/collator.rs +++ b/src/uucore/src/lib/features/i18n/collator.rs @@ -3,7 +3,8 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use std::{cmp::Ordering, sync::OnceLock}; +use std::cmp::Ordering; +use std::sync::OnceLock; use icu_collator::{self, CollatorBorrowed}; diff --git a/src/uucore/src/lib/features/i18n/datetime.rs b/src/uucore/src/lib/features/i18n/datetime.rs index 7c4e3c862fc..29617142bd2 100644 --- a/src/uucore/src/lib/features/i18n/datetime.rs +++ b/src/uucore/src/lib/features/i18n/datetime.rs @@ -9,8 +9,7 @@ use icu_calendar::Date; use icu_calendar::cal::{Buddhist, Ethiopian, Iso, Persian}; -use icu_datetime::DateTimeFormatter; -use icu_datetime::fieldsets; +use icu_datetime::{DateTimeFormatter, fieldsets}; use icu_locale::Locale; use jiff::civil::Date as JiffDate; use jiff_icu::ConvertFrom; diff --git a/src/uucore/src/lib/features/mode.rs b/src/uucore/src/lib/features/mode.rs index b6ce07aa9d5..acb2ec370c7 100644 --- a/src/uucore/src/lib/features/mode.rs +++ b/src/uucore/src/lib/features/mode.rs @@ -494,8 +494,7 @@ pub fn with_umask(mask: u32, operation: impl FnOnce() -> T) -> T { #[cfg(test)] mod tests { - use super::parse; - use super::parse_chmod; + use super::{parse, parse_chmod}; #[test] fn test_chmod_symbolic_modes() { diff --git a/src/uucore/src/lib/features/parser/num_parser.rs b/src/uucore/src/lib/features/parser/num_parser.rs index 72b893797cb..05b9611ae31 100644 --- a/src/uucore/src/lib/features/parser/num_parser.rs +++ b/src/uucore/src/lib/features/parser/num_parser.rs @@ -7,13 +7,9 @@ //! Utilities for parsing numbers in various formats -use bigdecimal::{ - BigDecimal, - num_bigint::{BigInt, BigUint, Sign}, -}; -use num_traits::Signed; -use num_traits::ToPrimitive; -use num_traits::Zero; +use bigdecimal::BigDecimal; +use bigdecimal::num_bigint::{BigInt, BigUint, Sign}; +use num_traits::{Signed, ToPrimitive, Zero}; use crate::extendedbigdecimal::ExtendedBigDecimal; diff --git a/src/uucore/src/lib/features/parser/parse_time.rs b/src/uucore/src/lib/features/parser/parse_time.rs index f1155443164..01db02ebb6c 100644 --- a/src/uucore/src/lib/features/parser/parse_time.rs +++ b/src/uucore/src/lib/features/parser/parse_time.rs @@ -9,14 +9,10 @@ //! //! Use the [`from_str`] function to parse a [`Duration`] from a string. -use crate::{ - display::Quotable, - extendedbigdecimal::ExtendedBigDecimal, - parser::num_parser::{self, ExtendedParserError, ParseTarget}, -}; -use num_traits::ToPrimitive; -use num_traits::Zero; -use num_traits::{FromPrimitive, Signed}; +use crate::display::Quotable; +use crate::extendedbigdecimal::ExtendedBigDecimal; +use crate::parser::num_parser::{self, ExtendedParserError, ParseTarget}; +use num_traits::{FromPrimitive, Signed, ToPrimitive, Zero}; use std::time::Duration; /// Parse a duration from a string. diff --git a/src/uucore/src/lib/features/parser/shortcut_value_parser.rs b/src/uucore/src/lib/features/parser/shortcut_value_parser.rs index 4fdda148b5b..7a397fdb208 100644 --- a/src/uucore/src/lib/features/parser/shortcut_value_parser.rs +++ b/src/uucore/src/lib/features/parser/shortcut_value_parser.rs @@ -8,10 +8,8 @@ //! A parser that accepts shortcuts for values. //! `ShortcutValueParser` is similar to clap's `PossibleValuesParser` -use clap::{ - builder::{PossibleValue, TypedValueParser}, - error::{ContextKind, ContextValue, ErrorKind}, -}; +use clap::builder::{PossibleValue, TypedValueParser}; +use clap::error::{ContextKind, ContextValue, ErrorKind}; use std::fmt::Write as _; /// A parser that accepts shortcuts for values. @@ -138,7 +136,9 @@ where mod tests { use std::ffi::OsStr; - use clap::{Command, builder::PossibleValue, builder::TypedValueParser, error::ErrorKind}; + use clap::Command; + use clap::builder::{PossibleValue, TypedValueParser}; + use clap::error::ErrorKind; use super::ShortcutValueParser; diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 3eb3dca9fae..1b82a92e042 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -31,8 +31,7 @@ use crate::features::safe_traversal::{DirFd, FileInfo, SymlinkBehavior}; use std::ffi::CString; use std::fs::Metadata; -use std::io::Error as IOError; -use std::io::Result as IOResult; +use std::io::{Error as IOError, Result as IOResult}; use std::os::unix::fs::MetadataExt; use std::os::unix::ffi::OsStrExt; diff --git a/src/uucore/src/lib/features/pipes.rs b/src/uucore/src/lib/features/pipes.rs index aa135a46e39..69d5c3172c5 100644 --- a/src/uucore/src/lib/features/pipes.rs +++ b/src/uucore/src/lib/features/pipes.rs @@ -7,11 +7,9 @@ use crate::io::{RawReader, RawWriter}; use rustix::pipe::{SpliceFlags, fcntl_setpipe_size}; -use std::{ - cell::Cell, - io::{PipeReader, PipeWriter, Read, Write}, - os::fd::AsFd, -}; +use std::cell::Cell; +use std::io::{PipeReader, PipeWriter, Read, Write}; +use std::os::fd::AsFd; pub const MAX_ROOTLESS_PIPE_SIZE: usize = 1024 * 1024; const KERNEL_DEFAULT_PIPE_SIZE: usize = 64 * 1024; diff --git a/src/uucore/src/lib/features/proc_info.rs b/src/uucore/src/lib/features/proc_info.rs index 3c114c0590a..93bb976dfe5 100644 --- a/src/uucore/src/lib/features/proc_info.rs +++ b/src/uucore/src/lib/features/proc_info.rs @@ -31,14 +31,12 @@ use crate::features::tty::Teletype; +use std::collections::HashMap; +use std::fmt::{self, Display, Formatter}; use std::hash::Hash; -use std::{ - collections::HashMap, - fmt::{self, Display, Formatter}, - fs, io, - path::PathBuf, - rc::Rc, -}; +use std::path::PathBuf; +use std::rc::Rc; +use std::{fs, io}; use walkdir::{DirEntry, WalkDir}; @@ -411,7 +409,8 @@ pub fn walk_process() -> impl Iterator { mod tests { use super::*; use crate::features::tty::Teletype; - use std::{collections::HashSet, str::FromStr}; + use std::collections::HashSet; + use std::str::FromStr; #[test] fn test_run_state_conversion() { diff --git a/src/uucore/src/lib/features/quoting_style/mod.rs b/src/uucore/src/lib/features/quoting_style/mod.rs index 75551692b5b..e9ea813a382 100644 --- a/src/uucore/src/lib/features/quoting_style/mod.rs +++ b/src/uucore/src/lib/features/quoting_style/mod.rs @@ -383,10 +383,8 @@ pub fn locale_aware_escape_dir_name(name: &OsStr, style: QuotingStyle) -> OsStri #[cfg(test)] mod tests { - use crate::{ - i18n::UEncoding, - quoting_style::{QuotingStyle, escape_control_chars, escape_name_inner}, - }; + use crate::i18n::UEncoding; + use crate::quoting_style::{QuotingStyle, escape_control_chars, escape_name_inner}; // spell-checker:ignore (tests/words) one\'two one'two diff --git a/src/uucore/src/lib/features/safe_traversal.rs b/src/uucore/src/lib/features/safe_traversal.rs index 2ebc460f1d6..4d1cb6325bb 100644 --- a/src/uucore/src/lib/features/safe_traversal.rs +++ b/src/uucore/src/lib/features/safe_traversal.rs @@ -17,8 +17,6 @@ use std::os::unix::ffi::OsStringExt; use std::ffi::{CStr, CString, OsStr, OsString}; -use std::fs; -use std::io; #[cfg(any(target_os = "linux", target_os = "android"))] use std::mem::MaybeUninit; use std::os::unix::ffi::OsStrExt; @@ -26,6 +24,7 @@ use std::os::unix::fs::MetadataExt; use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd}; use std::path::{Path, PathBuf}; use std::time::SystemTime; +use std::{fs, io}; #[cfg(not(any(target_os = "linux", target_os = "android")))] use nix::dir::Dir; @@ -1102,8 +1101,7 @@ impl MetadataExt for Metadata { mod tests { use super::*; use std::fs; - use std::os::unix::fs::MetadataExt; - use std::os::unix::fs::symlink; + use std::os::unix::fs::{MetadataExt, symlink}; use std::os::unix::io::IntoRawFd; use tempfile::TempDir; diff --git a/src/uucore/src/lib/features/signals.rs b/src/uucore/src/lib/features/signals.rs index 816f791c3f5..d858c9e7c34 100644 --- a/src/uucore/src/lib/features/signals.rs +++ b/src/uucore/src/lib/features/signals.rs @@ -844,10 +844,8 @@ pub const fn sigpipe_was_ignored() -> bool { #[cfg(target_os = "linux")] pub fn ensure_stdout_not_broken() -> std::io::Result { - use nix::{ - poll::{PollFd, PollFlags, PollTimeout, poll}, - sys::stat::{SFlag, fstat}, - }; + use nix::poll::{PollFd, PollFlags, PollTimeout, poll}; + use nix::sys::stat::{SFlag, fstat}; use std::io::stdout; use std::os::fd::AsFd; diff --git a/src/uucore/src/lib/features/sum.rs b/src/uucore/src/lib/features/sum.rs index d356489ab64..b65d3e752e2 100644 --- a/src/uucore/src/lib/features/sum.rs +++ b/src/uucore/src/lib/features/sum.rs @@ -726,9 +726,7 @@ mod tests { fn test_crlf_across_blocks() { use std::io::Write; - use super::Digest; - use super::DigestWriter; - use super::Md5; + use super::{Digest, DigestWriter, Md5}; // Writing "\r" in one call to `write()`, and then "\n" in another. let mut digest = Box::new(Md5::default()) as Box; diff --git a/src/uucore/src/lib/features/tty.rs b/src/uucore/src/lib/features/tty.rs index 9984edf954d..4c1dbf4d581 100644 --- a/src/uucore/src/lib/features/tty.rs +++ b/src/uucore/src/lib/features/tty.rs @@ -5,10 +5,8 @@ //! Set of functions to parsing TTY -use std::{ - fmt::{self, Display, Formatter}, - path::PathBuf, -}; +use std::fmt::{self, Display, Formatter}; +use std::path::PathBuf; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Teletype { diff --git a/src/uucore/src/lib/features/uptime/unix.rs b/src/uucore/src/lib/features/uptime/unix.rs index e36f1df0063..69da1aee1a5 100644 --- a/src/uucore/src/lib/features/uptime/unix.rs +++ b/src/uucore/src/lib/features/uptime/unix.rs @@ -96,8 +96,7 @@ pub fn get_uptime(_boot_time: Option) -> UResult { target_os = "openbsd", )))] pub fn get_uptime(boot_time: Option) -> UResult { - use crate::utmpx::BOOT_TIME; - use crate::utmpx::Utmpx; + use crate::utmpx::{BOOT_TIME, Utmpx}; use jiff::Timestamp; use std::fs::File; use std::io::Read; @@ -165,8 +164,7 @@ pub fn get_uptime(boot_time: Option) -> UResult { #[cfg(not(any(target_os = "openbsd", target_os = "android")))] // see: https://gitlab.com/procps-ng/procps/-/blob/4740a0efa79cade867cfc7b32955fe0f75bf5173/library/uptime.c#L63-L115 pub fn get_nusers() -> usize { - use crate::utmpx::USER_PROCESS; - use crate::utmpx::Utmpx; + use crate::utmpx::{USER_PROCESS, Utmpx}; let mut num_user = 0; Utmpx::iter_all_records().for_each(|ut| { diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index 34c4703b707..739872522e6 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -100,39 +100,25 @@ mod ut { pub const UT_IDSIZE: usize = 4; - pub use libc::ACCOUNTING; - pub use libc::BOOT_TIME; - pub use libc::DEAD_PROCESS; - pub use libc::EMPTY; - pub use libc::INIT_PROCESS; - pub use libc::LOGIN_PROCESS; - pub use libc::NEW_TIME; - pub use libc::OLD_TIME; - pub use libc::RUN_LVL; - pub use libc::USER_PROCESS; + pub use libc::{ + ACCOUNTING, BOOT_TIME, DEAD_PROCESS, EMPTY, INIT_PROCESS, LOGIN_PROCESS, NEW_TIME, + OLD_TIME, RUN_LVL, USER_PROCESS, + }; } #[cfg(target_vendor = "apple")] mod ut { pub static DEFAULT_FILE: &str = "/var/run/utmpx"; - pub use libc::_UTX_HOSTSIZE as UT_HOSTSIZE; - pub use libc::_UTX_IDSIZE as UT_IDSIZE; - pub use libc::_UTX_LINESIZE as UT_LINESIZE; - pub use libc::_UTX_USERSIZE as UT_NAMESIZE; + pub use libc::{ + _UTX_HOSTSIZE as UT_HOSTSIZE, _UTX_IDSIZE as UT_IDSIZE, _UTX_LINESIZE as UT_LINESIZE, + _UTX_USERSIZE as UT_NAMESIZE, + }; - pub use libc::ACCOUNTING; - pub use libc::BOOT_TIME; - pub use libc::DEAD_PROCESS; - pub use libc::EMPTY; - pub use libc::INIT_PROCESS; - pub use libc::LOGIN_PROCESS; - pub use libc::NEW_TIME; - pub use libc::OLD_TIME; - pub use libc::RUN_LVL; - pub use libc::SHUTDOWN_TIME; - pub use libc::SIGNATURE; - pub use libc::USER_PROCESS; + pub use libc::{ + ACCOUNTING, BOOT_TIME, DEAD_PROCESS, EMPTY, INIT_PROCESS, LOGIN_PROCESS, NEW_TIME, + OLD_TIME, RUN_LVL, SHUTDOWN_TIME, SIGNATURE, USER_PROCESS, + }; } #[cfg(target_os = "freebsd")] @@ -144,15 +130,10 @@ mod ut { pub const UT_IDSIZE: usize = 8; pub const UT_HOSTSIZE: usize = 128; - pub use libc::BOOT_TIME; - pub use libc::DEAD_PROCESS; - pub use libc::EMPTY; - pub use libc::INIT_PROCESS; - pub use libc::LOGIN_PROCESS; - pub use libc::NEW_TIME; - pub use libc::OLD_TIME; - pub use libc::SHUTDOWN_TIME; - pub use libc::USER_PROCESS; + pub use libc::{ + BOOT_TIME, DEAD_PROCESS, EMPTY, INIT_PROCESS, LOGIN_PROCESS, NEW_TIME, OLD_TIME, + SHUTDOWN_TIME, USER_PROCESS, + }; } #[cfg(target_os = "netbsd")] @@ -161,10 +142,10 @@ mod ut { pub const SHUTDOWN_TIME: usize = 11; - pub use libc::_UTX_HOSTSIZE as UT_HOSTSIZE; - pub use libc::_UTX_IDSIZE as UT_IDSIZE; - pub use libc::_UTX_LINESIZE as UT_LINESIZE; - pub use libc::_UTX_USERSIZE as UT_NAMESIZE; + pub use libc::{ + _UTX_HOSTSIZE as UT_HOSTSIZE, _UTX_IDSIZE as UT_IDSIZE, _UTX_LINESIZE as UT_LINESIZE, + _UTX_USERSIZE as UT_NAMESIZE, + }; pub use libc::ACCOUNTING; pub const BOOT_TIME: i16 = libc::BOOT_TIME as i16; @@ -183,19 +164,12 @@ mod ut { mod ut { pub static DEFAULT_FILE: &str = ""; - pub use libc::UT_HOSTSIZE; - pub use libc::UT_IDLEN; - pub use libc::UT_LINESIZE; - pub use libc::UT_NAMESIZE; + pub use libc::{UT_HOSTSIZE, UT_IDLEN, UT_LINESIZE, UT_NAMESIZE}; - pub use libc::BOOT_TIME; - pub use libc::DEAD_PROCESS; - pub use libc::INIT_PROCESS; - pub use libc::LOGIN_PROCESS; - pub use libc::NEW_TIME; - pub use libc::OLD_TIME; - pub use libc::RUN_LVL; - pub use libc::USER_PROCESS; + pub use libc::{ + BOOT_TIME, DEAD_PROCESS, INIT_PROCESS, LOGIN_PROCESS, NEW_TIME, OLD_TIME, RUN_LVL, + USER_PROCESS, + }; } /// A login record diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 7f58e384db1..0e51d706ff2 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -39,16 +39,9 @@ mod mods; // core cross-platform modules pub use uucore_procs::*; // * cross-platform modules -pub use crate::mods::clap_localization; -pub use crate::mods::display; -pub use crate::mods::error; #[cfg(all(feature = "fs", any(unix, windows, target_os = "wasi")))] pub use crate::mods::io; -pub use crate::mods::line_ending; -pub use crate::mods::locale; -pub use crate::mods::os; -pub use crate::mods::panic; -pub use crate::mods::posix; +pub use crate::mods::{clap_localization, display, error, line_ending, locale, os, panic, posix}; // * feature-gated modules #[cfg(feature = "backup-control")] @@ -57,12 +50,10 @@ pub use crate::features::backup_control; pub use crate::features::benchmark; #[cfg(feature = "buf-copy")] pub use crate::features::buf_copy; -pub use crate::features::char_width; #[cfg(feature = "checksum")] pub use crate::features::checksum; #[cfg(feature = "colors")] pub use crate::features::colors; -pub use crate::features::diagnostics; #[cfg(feature = "encoding")] pub use crate::features::encoding; #[cfg(feature = "extendedbigdecimal")] @@ -104,6 +95,7 @@ pub use crate::features::update_control; pub use crate::features::uptime; #[cfg(feature = "version-cmp")] pub use crate::features::version_cmp; +pub use crate::features::{char_width, diagnostics}; // * (platform-specific) feature-gated modules // ** non-windows (i.e. Unix + Fuchsia) @@ -190,14 +182,14 @@ use nix::sys::signal::{ use std::borrow::Cow; use std::ffi::{OsStr, OsString}; use std::io::{BufRead, BufReader}; -use std::iter; #[cfg(unix)] use std::os::unix::ffi::{OsStrExt, OsStringExt}; #[cfg(all(target_os = "wasi", target_env = "p1"))] use std::os::wasi::ffi::{OsStrExt, OsStringExt}; -use std::str; use std::str::Utf8Chunk; -use std::sync::{LazyLock, atomic::Ordering}; +use std::sync::LazyLock; +use std::sync::atomic::Ordering; +use std::{iter, str}; /// 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/mods/clap_localization.rs b/src/uucore/src/lib/mods/clap_localization.rs index 1048d11d27c..c9f8c343b55 100644 --- a/src/uucore/src/lib/mods/clap_localization.rs +++ b/src/uucore/src/lib/mods/clap_localization.rs @@ -21,8 +21,7 @@ use clap::{ArgMatches, Command, Error}; use std::error::Error as StdError; use std::ffi::OsString; -use std::io::Write as _; -use std::io::stderr; +use std::io::{Write as _, stderr}; /// Color enum for consistent styling #[derive(Debug, Clone, Copy)] diff --git a/src/uucore/src/lib/mods/display.rs b/src/uucore/src/lib/mods/display.rs index a011e355d0d..50174af6f13 100644 --- a/src/uucore/src/lib/mods/display.rs +++ b/src/uucore/src/lib/mods/display.rs @@ -25,11 +25,10 @@ //! # Ok::<(), std::io::Error>(()) //! ``` -use std::env; use std::ffi::OsStr; -use std::fmt; use std::fs::File; use std::io::{self, BufWriter, Stdout, StdoutLock, Write as _}; +use std::{env, fmt}; // These used to be defined here, but they live in their own crate now. pub use os_display::{Quotable, Quoted}; diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index 3d3d02f56be..58d54a7d2da 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -55,13 +55,11 @@ //! * Using [`ExitCode`] is not recommended but can be useful for converting utils to use //! [`UResult`]. -use std::{ - cell::Cell, - error::Error, - fmt::{Display, Formatter}, - io::Write, - sync::atomic::{AtomicI32, Ordering}, -}; +use std::cell::Cell; +use std::error::Error; +use std::fmt::{Display, Formatter}; +use std::io::Write; +use std::sync::atomic::{AtomicI32, Ordering}; static EXIT_CODE: AtomicI32 = AtomicI32::new(0); diff --git a/src/uucore/src/lib/mods/io.rs b/src/uucore/src/lib/mods/io.rs index f63949a44d4..e420cda9bd6 100644 --- a/src/uucore/src/lib/mods/io.rs +++ b/src/uucore/src/lib/mods/io.rs @@ -14,16 +14,14 @@ //! Even though they are distinct classes, they share common functionality. //! Access to this common functionality is provided in `OwnedFileDescriptorOrHandle`. +use std::fs::{File, OpenOptions}; +use std::io; #[cfg(not(windows))] use std::os::fd::{AsFd, OwnedFd}; #[cfg(windows)] use std::os::windows::io::{AsHandle, OwnedHandle}; -use std::{ - fs::{File, OpenOptions}, - io, - path::Path, - process::Stdio, -}; +use std::path::Path; +use std::process::Stdio; #[cfg(windows)] type NativeType = OwnedHandle; diff --git a/src/uucore/src/lib/mods/locale.rs b/src/uucore/src/lib/mods/locale.rs index dac7bff0ddd..7b61b5d5a2d 100644 --- a/src/uucore/src/lib/mods/locale.rs +++ b/src/uucore/src/lib/mods/locale.rs @@ -858,7 +858,8 @@ macro_rules! translate { } // Re-export the macros for easier access -pub use {translate, translate_text}; +pub use translate; +pub use translate_text; #[cfg(test)] mod tests { @@ -875,9 +876,8 @@ mod tests { "locale table uses a raw string; content containing `\"#` becomes code" ); } - use std::env; - use std::fs; use std::path::PathBuf; + use std::{env, fs}; use tempfile::TempDir; #[test]