1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #3299 from jfinkels/clippy-fixes-2022-03-22

clippy fixes from nightly rust
This commit is contained in:
Sylvestre Ledru 2022-03-23 08:39:20 +01:00 committed by GitHub
commit 1cd72a621a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 90 additions and 92 deletions

View file

@ -408,23 +408,21 @@ enum RecursiveMode {
impl RecursiveMode { impl RecursiveMode {
fn is_recursive(self) -> bool { fn is_recursive(self) -> bool {
match self { match self {
RecursiveMode::NotRecursive => false, Self::NotRecursive => false,
RecursiveMode::RecursiveButDoNotFollowSymLinks Self::RecursiveButDoNotFollowSymLinks
| RecursiveMode::RecursiveAndFollowAllDirSymLinks | Self::RecursiveAndFollowAllDirSymLinks
| RecursiveMode::RecursiveAndFollowArgDirSymLinks => true, | Self::RecursiveAndFollowArgDirSymLinks => true,
} }
} }
fn fts_open_options(self) -> c_int { fn fts_open_options(self) -> c_int {
match self { match self {
RecursiveMode::NotRecursive | RecursiveMode::RecursiveButDoNotFollowSymLinks => { Self::NotRecursive | Self::RecursiveButDoNotFollowSymLinks => fts_sys::FTS_PHYSICAL,
fts_sys::FTS_PHYSICAL
}
RecursiveMode::RecursiveAndFollowAllDirSymLinks => fts_sys::FTS_LOGICAL, Self::RecursiveAndFollowAllDirSymLinks => fts_sys::FTS_LOGICAL,
RecursiveMode::RecursiveAndFollowArgDirSymLinks => { Self::RecursiveAndFollowArgDirSymLinks => {
fts_sys::FTS_PHYSICAL | fts_sys::FTS_COMFOLLOW fts_sys::FTS_PHYSICAL | fts_sys::FTS_COMFOLLOW
} }
} }

View file

@ -55,25 +55,25 @@ impl UError for ChrootError {
impl Display for ChrootError { impl Display for ChrootError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
ChrootError::CannotEnter(s, e) => write!(f, "cannot chroot to {}: {}", s.quote(), e,), Self::CannotEnter(s, e) => write!(f, "cannot chroot to {}: {}", s.quote(), e,),
ChrootError::CommandFailed(s, e) => { Self::CommandFailed(s, e) => {
write!(f, "failed to run command {}: {}", s.to_string().quote(), e,) write!(f, "failed to run command {}: {}", s.to_string().quote(), e,)
} }
ChrootError::InvalidUserspec(s) => write!(f, "invalid userspec: {}", s.quote(),), Self::InvalidUserspec(s) => write!(f, "invalid userspec: {}", s.quote(),),
ChrootError::MissingNewRoot => write!( Self::MissingNewRoot => write!(
f, f,
"Missing operand: NEWROOT\nTry '{} --help' for more information.", "Missing operand: NEWROOT\nTry '{} --help' for more information.",
uucore::execution_phrase(), uucore::execution_phrase(),
), ),
ChrootError::NoSuchGroup(s) => write!(f, "no such group: {}", s.maybe_quote(),), Self::NoSuchGroup(s) => write!(f, "no such group: {}", s.maybe_quote(),),
ChrootError::NoSuchDirectory(s) => write!( Self::NoSuchDirectory(s) => write!(
f, f,
"cannot change root directory to {}: no such directory", "cannot change root directory to {}: no such directory",
s.quote(), s.quote(),
), ),
ChrootError::SetGidFailed(s, e) => write!(f, "cannot set gid to {}: {}", s, e), Self::SetGidFailed(s, e) => write!(f, "cannot set gid to {}: {}", s, e),
ChrootError::SetGroupsFailed(e) => write!(f, "cannot set groups: {}", e), Self::SetGroupsFailed(e) => write!(f, "cannot set groups: {}", e),
ChrootError::SetUserFailed(s, e) => { Self::SetUserFailed(s, e) => {
write!(f, "cannot set user to {}: {}", s.maybe_quote(), e) write!(f, "cannot set user to {}: {}", s.maybe_quote(), e)
} }
} }

View file

@ -1093,8 +1093,8 @@ fn copy_directory(
impl OverwriteMode { impl OverwriteMode {
fn verify(&self, path: &Path) -> CopyResult<()> { fn verify(&self, path: &Path) -> CopyResult<()> {
match *self { match *self {
OverwriteMode::NoClobber => Err(Error::NotAllFilesCopied), Self::NoClobber => Err(Error::NotAllFilesCopied),
OverwriteMode::Interactive(_) => { Self::Interactive(_) => {
if prompt_yes!("{}: overwrite {}? ", uucore::util_name(), path.quote()) { if prompt_yes!("{}: overwrite {}? ", uucore::util_name(), path.quote()) {
Ok(()) Ok(())
} else { } else {
@ -1104,7 +1104,7 @@ impl OverwriteMode {
))) )))
} }
} }
OverwriteMode::Clobber(_) => Ok(()), Self::Clobber(_) => Ok(()),
} }
} }
} }

View file

@ -100,16 +100,16 @@ impl std::fmt::Display for ParseError {
Self::StatusLevelNotRecognized(arg) => { Self::StatusLevelNotRecognized(arg) => {
write!(f, "status=LEVEL not recognized -> {}", arg) write!(f, "status=LEVEL not recognized -> {}", arg)
} }
ParseError::BsOutOfRange => { Self::BsOutOfRange => {
write!(f, "bs=N cannot fit into memory") write!(f, "bs=N cannot fit into memory")
} }
ParseError::IbsOutOfRange => { Self::IbsOutOfRange => {
write!(f, "ibs=N cannot fit into memory") write!(f, "ibs=N cannot fit into memory")
} }
ParseError::ObsOutOfRange => { Self::ObsOutOfRange => {
write!(f, "obs=N cannot fit into memory") write!(f, "obs=N cannot fit into memory")
} }
ParseError::CbsOutOfRange => { Self::CbsOutOfRange => {
write!(f, "cbs=N cannot fit into memory") write!(f, "cbs=N cannot fit into memory")
} }
Self::Unimplemented(arg) => { Self::Unimplemented(arg) => {

View file

@ -65,7 +65,7 @@ impl Token {
} }
} }
fn is_a_close_paren(&self) -> bool { fn is_a_close_paren(&self) -> bool {
matches!(*self, Token::ParClose) matches!(*self, Self::ParClose)
} }
} }

View file

@ -50,9 +50,9 @@ impl UError for GroupsError {}
impl Display for GroupsError { impl Display for GroupsError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
GroupsError::GetGroupsFailed => write!(f, "failed to fetch groups"), Self::GetGroupsFailed => write!(f, "failed to fetch groups"),
GroupsError::GroupNotFound(gid) => write!(f, "cannot find name for group ID {}", gid), Self::GroupNotFound(gid) => write!(f, "cannot find name for group ID {}", gid),
GroupsError::UserNotFound(user) => write!(f, "{}: no such user", user.quote()), Self::UserNotFound(user) => write!(f, "{}: no such user", user.quote()),
} }
} }
} }

View file

@ -473,8 +473,8 @@ impl UError for HashsumError {}
impl std::fmt::Display for HashsumError { impl std::fmt::Display for HashsumError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
HashsumError::InvalidRegex => write!(f, "invalid regular expression"), Self::InvalidRegex => write!(f, "invalid regular expression"),
HashsumError::InvalidFormat => Ok(()), Self::InvalidFormat => Ok(()),
} }
} }
} }

View file

@ -58,7 +58,7 @@ impl std::error::Error for NohupError {}
impl UError for NohupError { impl UError for NohupError {
fn code(&self) -> i32 { fn code(&self) -> i32 {
match self { match self {
NohupError::OpenFailed(code, _) | NohupError::OpenFailed2(code, _, _, _) => *code, Self::OpenFailed(code, _) | Self::OpenFailed2(code, _, _, _) => *code,
_ => 2, _ => 2,
} }
} }
@ -67,9 +67,9 @@ impl UError for NohupError {
impl Display for NohupError { impl Display for NohupError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self { match self {
NohupError::CannotDetach => write!(f, "Cannot detach from console"), Self::CannotDetach => write!(f, "Cannot detach from console"),
NohupError::CannotReplace(s, e) => write!(f, "Cannot replace {}: {}", s, e), Self::CannotReplace(s, e) => write!(f, "Cannot replace {}: {}", s, e),
NohupError::OpenFailed(_, e) => { Self::OpenFailed(_, e) => {
write!(f, "failed to open {}: {}", NOHUP_OUT.quote(), e) write!(f, "failed to open {}: {}", NOHUP_OUT.quote(), e)
} }
NohupError::OpenFailed2(_, e1, s, e2) => write!( NohupError::OpenFailed2(_, e1, s, e2) => write!(

View file

@ -42,23 +42,23 @@ pub enum RoundMethod {
impl RoundMethod { impl RoundMethod {
pub fn round(&self, f: f64) -> f64 { pub fn round(&self, f: f64) -> f64 {
match self { match self {
RoundMethod::Up => f.ceil(), Self::Up => f.ceil(),
RoundMethod::Down => f.floor(), Self::Down => f.floor(),
RoundMethod::FromZero => { Self::FromZero => {
if f < 0.0 { if f < 0.0 {
f.floor() f.floor()
} else { } else {
f.ceil() f.ceil()
} }
} }
RoundMethod::TowardsZero => { Self::TowardsZero => {
if f < 0.0 { if f < 0.0 {
f.ceil() f.ceil()
} else { } else {
f.floor() f.floor()
} }
} }
RoundMethod::Nearest => f.round(), Self::Nearest => f.round(),
} }
} }
} }

View file

@ -174,11 +174,11 @@ impl UError for PtxError {}
impl Display for PtxError { impl Display for PtxError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self { match self {
PtxError::DumbFormat => { Self::DumbFormat => {
write!(f, "There is no dumb format with GNU extensions disabled") write!(f, "There is no dumb format with GNU extensions disabled")
} }
PtxError::NotImplemented(s) => write!(f, "{} not implemented yet", s), Self::NotImplemented(s) => write!(f, "{} not implemented yet", s),
PtxError::ParseError(e) => e.fmt(f), Self::ParseError(e) => e.fmt(f),
} }
} }
} }

View file

@ -92,7 +92,7 @@ impl ExtendedBigDecimal {
/// The smallest integer greater than or equal to this number. /// The smallest integer greater than or equal to this number.
pub fn ceil(self) -> ExtendedBigInt { pub fn ceil(self) -> ExtendedBigInt {
match self { match self {
ExtendedBigDecimal::BigDecimal(x) => ExtendedBigInt::BigInt(ceil(x)), Self::BigDecimal(x) => ExtendedBigInt::BigInt(ceil(x)),
other => From::from(other), other => From::from(other),
} }
} }
@ -100,7 +100,7 @@ impl ExtendedBigDecimal {
/// The largest integer less than or equal to this number. /// The largest integer less than or equal to this number.
pub fn floor(self) -> ExtendedBigInt { pub fn floor(self) -> ExtendedBigInt {
match self { match self {
ExtendedBigDecimal::BigDecimal(x) => ExtendedBigInt::BigInt(floor(x)), Self::BigDecimal(x) => ExtendedBigInt::BigInt(floor(x)),
other => From::from(other), other => From::from(other),
} }
} }
@ -121,17 +121,17 @@ impl From<ExtendedBigInt> for ExtendedBigDecimal {
impl Display for ExtendedBigDecimal { impl Display for ExtendedBigDecimal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
ExtendedBigDecimal::BigDecimal(x) => { Self::BigDecimal(x) => {
let (n, p) = x.as_bigint_and_exponent(); let (n, p) = x.as_bigint_and_exponent();
match p { match p {
0 => Self::BigDecimal(BigDecimal::new(n * 10, 1)).fmt(f), 0 => Self::BigDecimal(BigDecimal::new(n * 10, 1)).fmt(f),
_ => x.fmt(f), _ => x.fmt(f),
} }
} }
ExtendedBigDecimal::Infinity => f32::INFINITY.fmt(f), Self::Infinity => f32::INFINITY.fmt(f),
ExtendedBigDecimal::MinusInfinity => f32::NEG_INFINITY.fmt(f), Self::MinusInfinity => f32::NEG_INFINITY.fmt(f),
ExtendedBigDecimal::MinusZero => (-0.0f32).fmt(f), Self::MinusZero => (-0.0f32).fmt(f),
ExtendedBigDecimal::Nan => "nan".fmt(f), Self::Nan => "nan".fmt(f),
} }
} }
} }

View file

@ -181,7 +181,7 @@ impl UError for SortError {
impl Display for SortError { impl Display for SortError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
SortError::Disorder { Self::Disorder {
file, file,
line_number, line_number,
line, line,
@ -199,7 +199,7 @@ impl Display for SortError {
Ok(()) Ok(())
} }
} }
SortError::OpenFailed { path, error } => { Self::OpenFailed { path, error } => {
write!( write!(
f, f,
"open failed: {}: {}", "open failed: {}: {}",
@ -207,10 +207,10 @@ impl Display for SortError {
strip_errno(error) strip_errno(error)
) )
} }
SortError::ParseKeyError { key, msg } => { Self::ParseKeyError { key, msg } => {
write!(f, "failed to parse key {}: {}", key.quote(), msg) write!(f, "failed to parse key {}: {}", key.quote(), msg)
} }
SortError::ReadFailed { path, error } => { Self::ReadFailed { path, error } => {
write!( write!(
f, f,
"cannot read: {}: {}", "cannot read: {}: {}",
@ -218,17 +218,17 @@ impl Display for SortError {
strip_errno(error) strip_errno(error)
) )
} }
SortError::OpenTmpFileFailed { error } => { Self::OpenTmpFileFailed { error } => {
write!(f, "failed to open temporary file: {}", strip_errno(error)) write!(f, "failed to open temporary file: {}", strip_errno(error))
} }
SortError::CompressProgExecutionFailed { code } => { Self::CompressProgExecutionFailed { code } => {
write!(f, "couldn't execute compress program: errno {}", code) write!(f, "couldn't execute compress program: errno {}", code)
} }
SortError::CompressProgTerminatedAbnormally { prog } => { Self::CompressProgTerminatedAbnormally { prog } => {
write!(f, "{} terminated abnormally", prog.quote()) write!(f, "{} terminated abnormally", prog.quote())
} }
SortError::TmpDirCreationFailed => write!(f, "could not create temporary directory"), Self::TmpDirCreationFailed => write!(f, "could not create temporary directory"),
SortError::Uft8Error { error } => write!(f, "{}", error), Self::Uft8Error { error } => write!(f, "{}", error),
} }
} }
} }
@ -247,13 +247,13 @@ enum SortMode {
impl SortMode { impl SortMode {
fn get_short_name(&self) -> Option<char> { fn get_short_name(&self) -> Option<char> {
match self { match self {
SortMode::Numeric => Some('n'), Self::Numeric => Some('n'),
SortMode::HumanNumeric => Some('h'), Self::HumanNumeric => Some('h'),
SortMode::GeneralNumeric => Some('g'), Self::GeneralNumeric => Some('g'),
SortMode::Month => Some('M'), Self::Month => Some('M'),
SortMode::Version => Some('V'), Self::Version => Some('V'),
SortMode::Random => Some('R'), Self::Random => Some('R'),
SortMode::Default => None, Self::Default => None,
} }
} }
} }

View file

@ -46,9 +46,9 @@ impl SuffixType {
/// The radix to use when representing the suffix string as digits. /// The radix to use when representing the suffix string as digits.
pub fn radix(&self) -> u8 { pub fn radix(&self) -> u8 {
match self { match self {
SuffixType::Alphabetic => 26, Self::Alphabetic => 26,
SuffixType::Decimal => 10, Self::Decimal => 10,
SuffixType::Hexadecimal => 16, Self::Hexadecimal => 16,
} }
} }
} }

View file

@ -37,20 +37,20 @@ pub enum BadSequence {
impl Display for BadSequence { impl Display for BadSequence {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
BadSequence::MissingCharClassName => writeln!(f, "missing character class name '[::]'"), Self::MissingCharClassName => writeln!(f, "missing character class name '[::]'"),
BadSequence::MissingEquivalentClassChar => { Self::MissingEquivalentClassChar => {
writeln!(f, "missing equivalence class character '[==]'") writeln!(f, "missing equivalence class character '[==]'")
} }
BadSequence::MultipleCharRepeatInSet2 => { Self::MultipleCharRepeatInSet2 => {
writeln!(f, "only one [c*] repeat construct may appear in string2") writeln!(f, "only one [c*] repeat construct may appear in string2")
} }
BadSequence::CharRepeatInSet1 => { Self::CharRepeatInSet1 => {
writeln!(f, "the [c*] repeat construct may not appear in string1") writeln!(f, "the [c*] repeat construct may not appear in string1")
} }
BadSequence::InvalidRepeatCount(count) => { Self::InvalidRepeatCount(count) => {
writeln!(f, "invalid repeat count '{}' in [c*n] construct", count) writeln!(f, "invalid repeat count '{}' in [c*n] construct", count)
} }
BadSequence::EmptySet2WhenNotTruncatingSet1 => { Self::EmptySet2WhenNotTruncatingSet1 => {
writeln!(f, "when not truncating set1, string2 must be non-empty") writeln!(f, "when not truncating set1, string2 must be non-empty")
} }
} }
@ -83,20 +83,20 @@ pub enum Sequence {
impl Sequence { impl Sequence {
pub fn flatten(&self) -> Box<dyn Iterator<Item = char>> { pub fn flatten(&self) -> Box<dyn Iterator<Item = char>> {
match self { match self {
Sequence::Char(c) => Box::new(std::iter::once(*c)), Self::Char(c) => Box::new(std::iter::once(*c)),
Sequence::CharRange(l, r) => Box::new((*l..=*r).flat_map(std::char::from_u32)), Self::CharRange(l, r) => Box::new((*l..=*r).flat_map(std::char::from_u32)),
Sequence::CharStar(c) => Box::new(std::iter::repeat(*c)), Self::CharStar(c) => Box::new(std::iter::repeat(*c)),
Sequence::CharRepeat(c, n) => Box::new(std::iter::repeat(*c).take(*n)), Self::CharRepeat(c, n) => Box::new(std::iter::repeat(*c).take(*n)),
Sequence::Alnum => Box::new(('0'..='9').chain('A'..='Z').chain('a'..='z')), Self::Alnum => Box::new(('0'..='9').chain('A'..='Z').chain('a'..='z')),
Sequence::Alpha => Box::new(('A'..='Z').chain('a'..='z')), Self::Alpha => Box::new(('A'..='Z').chain('a'..='z')),
Sequence::Blank => Box::new(unicode_table::BLANK.iter().cloned()), Self::Blank => Box::new(unicode_table::BLANK.iter().cloned()),
Sequence::Control => Box::new( Self::Control => Box::new(
(0..=31) (0..=31)
.chain(std::iter::once(127)) .chain(std::iter::once(127))
.flat_map(std::char::from_u32), .flat_map(std::char::from_u32),
), ),
Sequence::Digit => Box::new('0'..='9'), Self::Digit => Box::new('0'..='9'),
Sequence::Graph => Box::new( Self::Graph => Box::new(
(48..=57) // digit (48..=57) // digit
.chain(65..=90) // uppercase .chain(65..=90) // uppercase
.chain(97..=122) // lowercase .chain(97..=122) // lowercase
@ -108,8 +108,8 @@ impl Sequence {
.chain(std::iter::once(32)) // space .chain(std::iter::once(32)) // space
.flat_map(std::char::from_u32), .flat_map(std::char::from_u32),
), ),
Sequence::Lower => Box::new('a'..='z'), Self::Lower => Box::new('a'..='z'),
Sequence::Print => Box::new( Self::Print => Box::new(
(48..=57) // digit (48..=57) // digit
.chain(65..=90) // uppercase .chain(65..=90) // uppercase
.chain(97..=122) // lowercase .chain(97..=122) // lowercase
@ -120,16 +120,16 @@ impl Sequence {
.chain(123..=126) .chain(123..=126)
.flat_map(std::char::from_u32), .flat_map(std::char::from_u32),
), ),
Sequence::Punct => Box::new( Self::Punct => Box::new(
(33..=47) (33..=47)
.chain(58..=64) .chain(58..=64)
.chain(91..=96) .chain(91..=96)
.chain(123..=126) .chain(123..=126)
.flat_map(std::char::from_u32), .flat_map(std::char::from_u32),
), ),
Sequence::Space => Box::new(unicode_table::SPACES.iter().cloned()), Self::Space => Box::new(unicode_table::SPACES.iter().cloned()),
Sequence::Upper => Box::new('A'..='Z'), Self::Upper => Box::new('A'..='Z'),
Sequence::Xdigit => Box::new(('0'..='9').chain('A'..='F').chain('a'..='f')), Self::Xdigit => Box::new(('0'..='9').chain('A'..='F').chain('a'..='f')),
} }
} }

View file

@ -620,7 +620,7 @@ impl From<i32> for Box<dyn UError> {
/// Implementations for clap::Error /// Implementations for clap::Error
impl UError for clap::Error { impl UError for clap::Error {
fn code(&self) -> i32 { fn code(&self) -> i32 {
match self.kind { match self.kind() {
clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion => 0, clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion => 0,
_ => 1, _ => 1,
} }