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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/uucore/src/lib/features/backup_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions src/uucore/src/lib/features/buf_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
8 changes: 2 additions & 6 deletions src/uucore/src/lib/features/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 2 additions & 5 deletions src/uucore/src/lib/features/extendedbigdecimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/uucore/src/lib/features/fast_inc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
17 changes: 6 additions & 11 deletions src/uucore/src/lib/features/format/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
22 changes: 9 additions & 13 deletions src/uucore/src/lib/features/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 5 additions & 10 deletions src/uucore/src/lib/features/format/num_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
fn fmt(&self, writer: impl Write, x: T) -> std::io::Result<()>;
Expand Down Expand Up @@ -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};

Expand Down
16 changes: 10 additions & 6 deletions src/uucore/src/lib/features/format/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
9 changes: 4 additions & 5 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/uucore/src/lib/features/fsext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ 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)]
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)]
Expand Down Expand Up @@ -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<Self> {
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
Expand Down
3 changes: 1 addition & 2 deletions src/uucore/src/lib/features/fsext/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
3 changes: 2 additions & 1 deletion src/uucore/src/lib/features/i18n/collator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
3 changes: 1 addition & 2 deletions src/uucore/src/lib/features/i18n/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/uucore/src/lib/features/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,7 @@ pub fn with_umask<T>(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() {
Expand Down
10 changes: 3 additions & 7 deletions src/uucore/src/lib/features/parser/num_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@

//! 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;

// 2^-30 seconds < 1 ns.
const SUBNANOSECOND_BINARY_EXPONENT: i32 = -30;

Check warning on line 17 in src/uucore/src/lib/features/parser/num_parser.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'SUBNANOSECOND' (file:'src/uucore/src/lib/features/parser/num_parser.rs', line:17)

/// Base for number parsing
#[derive(Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -556,7 +552,7 @@
&& base == Base::Hexadecimal
&& !digits.is_zero()
&& BigInt::from(digits.bits()) + &exponent - BigInt::from(scale) * 4
<= BigInt::from(SUBNANOSECOND_BINARY_EXPONENT)

Check warning on line 555 in src/uucore/src/lib/features/parser/num_parser.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'SUBNANOSECOND' (file:'src/uucore/src/lib/features/parser/num_parser.rs', line:555)
{
Err(make_error(false, negative))
} else {
Expand Down
12 changes: 4 additions & 8 deletions src/uucore/src/lib/features/parser/parse_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -202,7 +198,7 @@
);

// Neither fractional zeros nor a negative exponent alone imply that
// the duration underflows: the other factors can compensate for them.

Check warning on line 201 in src/uucore/src/lib/features/parser/parse_time.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'underflows' (file:'src/uucore/src/lib/features/parser/parse_time.rs', line:201)
assert_eq!(
from_str("0x.00000001p32", false),
Ok(Duration::from_secs(1))
Expand Down
10 changes: 5 additions & 5 deletions src/uucore/src/lib/features/parser/shortcut_value_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/uucore/src/lib/features/perms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions src/uucore/src/lib/features/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading
Loading