1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #3720 from andrewbaptist/fix_warnings

Update to handle all the latest cargo warnings
This commit is contained in:
Sylvestre Ledru 2022-07-19 11:40:38 +02:00 committed by GitHub
commit e16545723d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 138 additions and 139 deletions

View file

@ -62,8 +62,8 @@ enum LineReader {
impl LineReader { impl LineReader {
fn read_line(&mut self, buf: &mut String) -> io::Result<usize> { fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
match *self { match *self {
LineReader::Stdin(ref mut r) => r.read_line(buf), Self::Stdin(ref mut r) => r.read_line(buf),
LineReader::FileIn(ref mut r) => r.read_line(buf), Self::FileIn(ref mut r) => r.read_line(buf),
} }
} }
} }

View file

@ -1519,7 +1519,7 @@ fn copy_link(
} }
dest.into() dest.into()
}; };
symlink_file(&link, &dest, &*context_for(&link, &dest), symlinked_files) symlink_file(&link, &dest, &context_for(&link, &dest), symlinked_files)
} }
/// Copies `source` to `dest` using copy-on-write if possible. /// Copies `source` to `dest` using copy-on-write if possible.

View file

@ -23,11 +23,11 @@ pub enum Pattern {
impl ToString for Pattern { impl ToString for Pattern {
fn to_string(&self) -> String { fn to_string(&self) -> String {
match self { match self {
Pattern::UpToLine(n, _) => n.to_string(), Self::UpToLine(n, _) => n.to_string(),
Pattern::UpToMatch(regex, 0, _) => format!("/{}/", regex.as_str()), Self::UpToMatch(regex, 0, _) => format!("/{}/", regex.as_str()),
Pattern::UpToMatch(regex, offset, _) => format!("/{}/{:+}", regex.as_str(), offset), Self::UpToMatch(regex, offset, _) => format!("/{}/{:+}", regex.as_str(), offset),
Pattern::SkipToMatch(regex, 0, _) => format!("%{}%", regex.as_str()), Self::SkipToMatch(regex, 0, _) => format!("%{}%", regex.as_str()),
Pattern::SkipToMatch(regex, offset, _) => format!("%{}%{:+}", regex.as_str(), offset), Self::SkipToMatch(regex, offset, _) => format!("%{}%{:+}", regex.as_str(), offset),
} }
} }
} }

View file

@ -41,7 +41,7 @@ pub(crate) struct IConvFlags {
} }
/// Stores all Conv Flags that apply to the output /// Stores all Conv Flags that apply to the output
#[derive(Debug, Default, PartialEq)] #[derive(Debug, Default, PartialEq, Eq)]
pub struct OConvFlags { pub struct OConvFlags {
pub sparse: bool, pub sparse: bool,
pub excl: bool, pub excl: bool,
@ -52,7 +52,7 @@ pub struct OConvFlags {
} }
/// Stores all Flags that apply to the input /// Stores all Flags that apply to the input
#[derive(Debug, Default, PartialEq)] #[derive(Debug, Default, PartialEq, Eq)]
pub struct IFlags { pub struct IFlags {
pub cio: bool, pub cio: bool,
pub direct: bool, pub direct: bool,
@ -73,7 +73,7 @@ pub struct IFlags {
} }
/// Stores all Flags that apply to the output /// Stores all Flags that apply to the output
#[derive(Debug, Default, PartialEq)] #[derive(Debug, Default, PartialEq, Eq)]
pub struct OFlags { pub struct OFlags {
pub append: bool, pub append: bool,
pub cio: bool, pub cio: bool,
@ -96,7 +96,7 @@ pub struct OFlags {
/// Defaults to Reads(N) /// Defaults to Reads(N)
/// if iflag=count_bytes /// if iflag=count_bytes
/// then becomes Bytes(N) /// then becomes Bytes(N)
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum CountType { pub enum CountType {
Reads(u64), Reads(u64),
Bytes(u64), Bytes(u64),

View file

@ -18,7 +18,7 @@ use uucore::show_warning;
pub type Matches = ArgMatches; pub type Matches = ArgMatches;
/// Parser Errors describe errors with parser input /// Parser Errors describe errors with parser input
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum ParseError { pub enum ParseError {
MultipleFmtTable, MultipleFmtTable,
MultipleUCaseLCase, MultipleUCaseLCase,

View file

@ -36,7 +36,7 @@ static LONG_HELP: &str = "
mod colors; mod colors;
use self::colors::INTERNAL_DB; use self::colors::INTERNAL_DB;
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub enum OutputFmt { pub enum OutputFmt {
Shell, Shell,
CShell, CShell,

View file

@ -432,15 +432,15 @@ enum DuError {
impl Display for DuError { impl Display for DuError {
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 {
DuError::InvalidMaxDepthArg(s) => write!(f, "invalid maximum depth {}", s.quote()), Self::InvalidMaxDepthArg(s) => write!(f, "invalid maximum depth {}", s.quote()),
DuError::SummarizeDepthConflict(s) => { Self::SummarizeDepthConflict(s) => {
write!( write!(
f, f,
"summarizing conflicts with --max-depth={}", "summarizing conflicts with --max-depth={}",
s.maybe_quote() s.maybe_quote()
) )
} }
DuError::InvalidTimeStyleArg(s) => write!( Self::InvalidTimeStyleArg(s) => write!(
f, f,
"invalid argument {} for 'time style' "invalid argument {} for 'time style'
Valid arguments are: Valid arguments are:
@ -451,13 +451,13 @@ Try '{} --help' for more information.",
s.quote(), s.quote(),
uucore::execution_phrase() uucore::execution_phrase()
), ),
DuError::InvalidTimeArg(s) => write!( Self::InvalidTimeArg(s) => write!(
f, f,
"Invalid argument {} for --time. "Invalid argument {} for --time.
'birth' and 'creation' arguments are not supported on this platform.", 'birth' and 'creation' arguments are not supported on this platform.",
s.quote() s.quote()
), ),
DuError::InvalidGlob(s) => write!(f, "Invalid exclude syntax: {}", s), Self::InvalidGlob(s) => write!(f, "Invalid exclude syntax: {}", s),
} }
} }
} }

View file

@ -42,13 +42,13 @@ impl AstNode {
print!("\t",); print!("\t",);
} }
match self { match self {
AstNode::Leaf { token_idx, value } => println!( Self::Leaf { token_idx, value } => println!(
"Leaf( {} ) at #{} ( evaluate -> {:?} )", "Leaf( {} ) at #{} ( evaluate -> {:?} )",
value, value,
token_idx, token_idx,
self.evaluate() self.evaluate()
), ),
AstNode::Node { Self::Node {
token_idx, token_idx,
op_type, op_type,
operands, operands,
@ -157,7 +157,7 @@ impl AstNode {
} }
} }
pub fn operand_values(&self) -> Result<Vec<String>, String> { pub fn operand_values(&self) -> Result<Vec<String>, String> {
if let AstNode::Node { operands, .. } = self { if let Self::Node { operands, .. } = self {
let mut out = Vec::with_capacity(operands.len()); let mut out = Vec::with_capacity(operands.len());
for operand in operands { for operand in operands {
let value = operand.evaluate()?; let value = operand.evaluate()?;

View file

@ -135,7 +135,7 @@ struct PrimeHeap {
impl PrimeHeap { impl PrimeHeap {
fn peek(&self) -> Option<(u64, u64)> { fn peek(&self) -> Option<(u64, u64)> {
if let Some(&(x, y)) = self.data.get(0) { if let Some(&(x, y)) = self.data.first() {
Some((x, y)) Some((x, y))
} else { } else {
None None

View file

@ -11,7 +11,8 @@ extern crate uucore;
use std::error::Error; use std::error::Error;
use std::fmt::Write as FmtWrite; use std::fmt::Write as FmtWrite;
use std::io::{self, stdin, stdout, BufRead, Write}; use std::io::BufRead;
use std::io::{self, stdin, stdout, Write};
mod factor; mod factor;
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, Command};

View file

@ -70,7 +70,7 @@ impl<T: DoubleInt> Montgomery<T> {
debug_assert!(x < (self.n.as_double_width()) << t_bits); debug_assert!(x < (self.n.as_double_width()) << t_bits);
// TODO: optimize // TODO: optimize
let Montgomery { a, n } = self; let Self { a, n } = self;
let m = T::from_double_width(x).wrapping_mul(a); let m = T::from_double_width(x).wrapping_mul(a);
let nm = (n.as_double_width()) * (m.as_double_width()); let nm = (n.as_double_width()) * (m.as_double_width());
let (xnm, overflow) = x.overflowing_add(&nm); // x + n*m let (xnm, overflow) = x.overflowing_add(&nm); // x + n*m

View file

@ -40,16 +40,16 @@ impl Line {
// when we know that it's a FormatLine, as in the ParagraphStream iterator // when we know that it's a FormatLine, as in the ParagraphStream iterator
fn get_formatline(self) -> FileLine { fn get_formatline(self) -> FileLine {
match self { match self {
Line::FormatLine(fl) => fl, Self::FormatLine(fl) => fl,
Line::NoFormatLine(..) => panic!("Found NoFormatLine when expecting FormatLine"), Self::NoFormatLine(..) => panic!("Found NoFormatLine when expecting FormatLine"),
} }
} }
// when we know that it's a NoFormatLine, as in the ParagraphStream iterator // when we know that it's a NoFormatLine, as in the ParagraphStream iterator
fn get_noformatline(self) -> (String, bool) { fn get_noformatline(self) -> (String, bool) {
match self { match self {
Line::NoFormatLine(s, b) => (s, b), Self::NoFormatLine(s, b) => (s, b),
Line::FormatLine(..) => panic!("Found FormatLine when expecting NoFormatLine"), Self::FormatLine(..) => panic!("Found FormatLine when expecting NoFormatLine"),
} }
} }
} }

View file

@ -6,7 +6,7 @@
use std::ffi::OsString; use std::ffi::OsString;
use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::parse_size::{parse_size, ParseSizeError};
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub enum ParseError { pub enum ParseError {
Syntax, Syntax,
Overflow, Overflow,

View file

@ -73,7 +73,7 @@ enum InstallError {
impl UError for InstallError { impl UError for InstallError {
fn code(&self) -> i32 { fn code(&self) -> i32 {
match self { match self {
InstallError::Unimplemented(_) => 2, Self::Unimplemented(_) => 2,
_ => 1, _ => 1,
} }
} }
@ -87,41 +87,40 @@ impl Error for InstallError {}
impl Display for InstallError { impl Display for InstallError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use InstallError as IE;
match self { match self {
IE::Unimplemented(opt) => write!(f, "Unimplemented feature: {}", opt), Self::Unimplemented(opt) => write!(f, "Unimplemented feature: {}", opt),
IE::DirNeedsArg() => { Self::DirNeedsArg() => {
write!( write!(
f, f,
"{} with -d requires at least one argument.", "{} with -d requires at least one argument.",
uucore::util_name() uucore::util_name()
) )
} }
IE::CreateDirFailed(dir, e) => { Self::CreateDirFailed(dir, e) => {
Display::fmt(&uio_error!(e, "failed to create {}", dir.quote()), f) Display::fmt(&uio_error!(e, "failed to create {}", dir.quote()), f)
} }
IE::ChmodFailed(file) => write!(f, "failed to chmod {}", file.quote()), Self::ChmodFailed(file) => write!(f, "failed to chmod {}", file.quote()),
IE::InvalidTarget(target) => write!( Self::InvalidTarget(target) => write!(
f, f,
"invalid target {}: No such file or directory", "invalid target {}: No such file or directory",
target.quote() target.quote()
), ),
IE::TargetDirIsntDir(target) => { Self::TargetDirIsntDir(target) => {
write!(f, "target {} is not a directory", target.quote()) write!(f, "target {} is not a directory", target.quote())
} }
IE::BackupFailed(from, to, e) => Display::fmt( Self::BackupFailed(from, to, e) => Display::fmt(
&uio_error!(e, "cannot backup {} to {}", from.quote(), to.quote()), &uio_error!(e, "cannot backup {} to {}", from.quote(), to.quote()),
f, f,
), ),
IE::InstallFailed(from, to, e) => Display::fmt( Self::InstallFailed(from, to, e) => Display::fmt(
&uio_error!(e, "cannot install {} to {}", from.quote(), to.quote()), &uio_error!(e, "cannot install {} to {}", from.quote(), to.quote()),
f, f,
), ),
IE::StripProgramFailed(msg) => write!(f, "strip program failed: {}", msg), Self::StripProgramFailed(msg) => write!(f, "strip program failed: {}", msg),
IE::MetadataFailed(e) => Display::fmt(&uio_error!(e, ""), f), Self::MetadataFailed(e) => Display::fmt(&uio_error!(e, ""), f),
IE::NoSuchUser(user) => write!(f, "no such user: {}", user.maybe_quote()), Self::NoSuchUser(user) => write!(f, "no such user: {}", user.maybe_quote()),
IE::NoSuchGroup(group) => write!(f, "no such group: {}", group.maybe_quote()), Self::NoSuchGroup(group) => write!(f, "no such group: {}", group.maybe_quote()),
IE::OmittingDirectory(dir) => write!(f, "omitting directory {}", dir.quote()), Self::OmittingDirectory(dir) => write!(f, "omitting directory {}", dir.quote()),
} }
} }
} }

View file

@ -43,8 +43,8 @@ impl Error for JoinError {}
impl Display for JoinError { impl Display for JoinError {
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 {
JoinError::IOError(e) => write!(f, "io error: {}", e), Self::IOError(e) => write!(f, "io error: {}", e),
JoinError::UnorderedInput(e) => f.write_str(e), Self::UnorderedInput(e) => f.write_str(e),
} }
} }
} }

View file

@ -155,11 +155,11 @@ enum LsError {
impl UError for LsError { impl UError for LsError {
fn code(&self) -> i32 { fn code(&self) -> i32 {
match self { match self {
LsError::InvalidLineWidth(_) => 2, Self::InvalidLineWidth(_) => 2,
LsError::IOError(_) => 1, Self::IOError(_) => 1,
LsError::IOErrorContext(_, _) => 1, Self::IOErrorContext(_, _) => 1,
LsError::BlockSizeParseError(_) => 1, Self::BlockSizeParseError(_) => 1,
LsError::AlreadyListedError(_) => 2, Self::AlreadyListedError(_) => 2,
} }
} }
} }
@ -169,12 +169,12 @@ impl Error for LsError {}
impl Display for LsError { impl Display for LsError {
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 {
LsError::BlockSizeParseError(s) => { Self::BlockSizeParseError(s) => {
write!(f, "invalid --block-size argument {}", s.quote()) write!(f, "invalid --block-size argument {}", s.quote())
} }
LsError::InvalidLineWidth(s) => write!(f, "invalid line width: {}", s.quote()), Self::InvalidLineWidth(s) => write!(f, "invalid line width: {}", s.quote()),
LsError::IOError(e) => write!(f, "general io error: {}", e), Self::IOError(e) => write!(f, "general io error: {}", e),
LsError::IOErrorContext(e, p) => { Self::IOErrorContext(e, p) => {
let error_kind = e.kind(); let error_kind = e.kind();
let errno = e.raw_os_error().unwrap_or(1i32); let errno = e.raw_os_error().unwrap_or(1i32);
@ -236,7 +236,7 @@ impl Display for LsError {
}, },
} }
} }
LsError::AlreadyListedError(path) => { Self::AlreadyListedError(path) => {
write!( write!(
f, f,
"{}: not listing already-listed directory", "{}: not listing already-listed directory",

View file

@ -22,22 +22,22 @@ impl UError for MvError {}
impl Display for MvError { impl Display for MvError {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
match self { match self {
MvError::NoSuchFile(s) => write!(f, "cannot stat {}: No such file or directory", s), Self::NoSuchFile(s) => write!(f, "cannot stat {}: No such file or directory", s),
MvError::SameFile(s, t) => write!(f, "{} and {} are the same file", s, t), Self::SameFile(s, t) => write!(f, "{} and {} are the same file", s, t),
MvError::SelfSubdirectory(s) => write!( Self::SelfSubdirectory(s) => write!(
f, f,
"cannot move '{s}' to a subdirectory of itself, '{s}/{s}'", "cannot move '{s}' to a subdirectory of itself, '{s}/{s}'",
s = s s = s
), ),
MvError::DirectoryToNonDirectory(t) => { Self::DirectoryToNonDirectory(t) => {
write!(f, "cannot overwrite directory {} with non-directory", t) write!(f, "cannot overwrite directory {} with non-directory", t)
} }
MvError::NonDirectoryToDirectory(s, t) => write!( Self::NonDirectoryToDirectory(s, t) => write!(
f, f,
"cannot overwrite non-directory {} with directory {}", "cannot overwrite non-directory {} with directory {}",
t, s t, s
), ),
MvError::NotADirectory(t) => write!(f, "target {} is not a directory", t), Self::NotADirectory(t) => write!(f, "target {} is not a directory", t),
} }
} }
} }

View file

@ -72,7 +72,7 @@ impl Display for NohupError {
Self::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!( Self::OpenFailed2(_, e1, s, e2) => write!(
f, f,
"failed to open {}: {}\nfailed to open {}: {}", "failed to open {}: {}\nfailed to open {}: {}",
NOHUP_OUT.quote(), NOHUP_OUT.quote(),

View file

@ -19,9 +19,9 @@ pub enum NumfmtError {
impl UError for NumfmtError { impl UError for NumfmtError {
fn code(&self) -> i32 { fn code(&self) -> i32 {
match self { match self {
NumfmtError::IoError(_) => 1, Self::IoError(_) => 1,
NumfmtError::IllegalArgument(_) => 1, Self::IllegalArgument(_) => 1,
NumfmtError::FormattingError(_) => 2, Self::FormattingError(_) => 2,
} }
} }
} }
@ -31,9 +31,9 @@ impl Error for NumfmtError {}
impl Display for NumfmtError { impl Display for NumfmtError {
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 {
NumfmtError::IoError(s) Self::IoError(s) | Self::IllegalArgument(s) | Self::FormattingError(s) => {
| NumfmtError::IllegalArgument(s) write!(f, "{}", s)
| NumfmtError::FormattingError(s) => write!(f, "{}", s), }
} }
} }
} }

View file

@ -44,7 +44,7 @@ pub struct DisplayableSuffix(pub Suffix);
impl fmt::Display for DisplayableSuffix { impl fmt::Display for DisplayableSuffix {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let DisplayableSuffix((ref raw_suffix, ref with_i)) = *self; let Self((ref raw_suffix, ref with_i)) = *self;
match raw_suffix { match raw_suffix {
RawSuffix::K => write!(f, "K"), RawSuffix::K => write!(f, "K"),
RawSuffix::M => write!(f, "M"), RawSuffix::M => write!(f, "M"),

View file

@ -35,15 +35,15 @@ impl Eq for FormatWriter {}
impl fmt::Debug for FormatWriter { impl fmt::Debug for FormatWriter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
FormatWriter::IntWriter(ref p) => { Self::IntWriter(ref p) => {
f.write_str("IntWriter:")?; f.write_str("IntWriter:")?;
fmt::Pointer::fmt(p, f) fmt::Pointer::fmt(p, f)
} }
FormatWriter::FloatWriter(ref p) => { Self::FloatWriter(ref p) => {
f.write_str("FloatWriter:")?; f.write_str("FloatWriter:")?;
fmt::Pointer::fmt(p, f) fmt::Pointer::fmt(p, f)
} }
FormatWriter::MultibyteWriter(ref p) => { Self::MultibyteWriter(ref p) => {
f.write_str("MultibyteWriter:")?; f.write_str("MultibyteWriter:")?;
fmt::Pointer::fmt(&(*p as *const ()), f) fmt::Pointer::fmt(&(*p as *const ()), f)
} }

View file

@ -218,8 +218,10 @@ impl OdOptions {
"Radix must be one of [d, o, n, x]".to_string(), "Radix must be one of [d, o, n, x]".to_string(),
)); ));
} else { } else {
let radix: char = let radix: char = *(st
*(st.get(0).expect("byte string of length 1 lacks a 0th elem")) as char; .first()
.expect("byte string of length 1 lacks a 0th elem"))
as char;
match radix { match radix {
'd' => Radix::Decimal, 'd' => Radix::Decimal,
'x' => Radix::Hexadecimal, 'x' => Radix::Hexadecimal,

View file

@ -29,7 +29,7 @@ impl CommandLineOpts for ArgMatches {
/// and an optional label. Offset and label are specified in bytes. /// and an optional label. Offset and label are specified in bytes.
/// `FileAndOffset` will be only used if an offset is specified, /// `FileAndOffset` will be only used if an offset is specified,
/// but it might be 0. /// but it might be 0.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub enum CommandLineInputs { pub enum CommandLineInputs {
FileNames(Vec<String>), FileNames(Vec<String>),
FileAndOffset((String, u64, Option<u64>)), FileAndOffset((String, u64, Option<u64>)),

View file

@ -580,7 +580,7 @@ fn build_options(
let date_time = Local::now(); let date_time = Local::now();
date_time.format("%b %d %H:%M %Y").to_string() date_time.format("%b %d %H:%M %Y").to_string()
} else { } else {
file_last_modified_time(paths.get(0).unwrap()) file_last_modified_time(paths.first().unwrap())
}; };
// +page option is less priority than --pages // +page option is less priority than --pages

View file

@ -24,16 +24,16 @@ impl Number {
// requires an addition implementation, and we don't want to // requires an addition implementation, and we don't want to
// implement that here. // implement that here.
match self { match self {
Number::Int(n) => n.is_zero(), Self::Int(n) => n.is_zero(),
Number::Float(x) => x.is_zero(), Self::Float(x) => x.is_zero(),
} }
} }
/// Convert this number into an `ExtendedBigDecimal`. /// Convert this number into an `ExtendedBigDecimal`.
pub fn into_extended_big_decimal(self) -> ExtendedBigDecimal { pub fn into_extended_big_decimal(self) -> ExtendedBigDecimal {
match self { match self {
Number::Int(n) => ExtendedBigDecimal::from(n), Self::Int(n) => ExtendedBigDecimal::from(n),
Number::Float(x) => x, Self::Float(x) => x,
} }
} }
@ -54,11 +54,11 @@ impl Number {
// If this number is already an integer, it is already // If this number is already an integer, it is already
// rounded to the nearest integer in the direction of // rounded to the nearest integer in the direction of
// `other`. // `other`.
Number::Int(num) => num, Self::Int(num) => num,
// Otherwise, if this number is a float, we need to decide // Otherwise, if this number is a float, we need to decide
// whether `other` is larger or smaller than it, and thus // whether `other` is larger or smaller than it, and thus
// whether to round up or round down, respectively. // whether to round up or round down, respectively.
Number::Float(num) => { Self::Float(num) => {
let other: ExtendedBigDecimal = From::from(other.clone()); let other: ExtendedBigDecimal = From::from(other.clone());
if other > num { if other > num {
num.ceil() num.ceil()

View file

@ -17,7 +17,7 @@ use crate::number::Number;
use crate::number::PreciseNumber; use crate::number::PreciseNumber;
/// An error returned when parsing a number fails. /// An error returned when parsing a number fails.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum ParseNumberError { pub enum ParseNumberError {
Float, Float,
Nan, Nan,

View file

@ -483,7 +483,7 @@ fn wipe_file(
for _ in 0..n_full_arrays { for _ in 0..n_full_arrays {
for p in &PATTERNS { for p in &PATTERNS {
pass_sequence.push(PassType::Pattern(*p)); pass_sequence.push(PassType::Pattern(p));
} }
} }
for pattern in PATTERNS.iter().take(remainder) { for pattern in PATTERNS.iter().take(remainder) {

View file

@ -22,12 +22,12 @@ enum Sign {
Positive, Positive,
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub struct NumInfo { pub struct NumInfo {
exponent: i64, exponent: i64,
sign: Sign, sign: Sign,
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub struct NumInfoParseSettings { pub struct NumInfoParseSettings {
pub accept_si_units: bool, pub accept_si_units: bool,
pub thousands_separator: Option<char>, pub thousands_separator: Option<char>,

View file

@ -171,7 +171,7 @@ impl Error for SortError {}
impl UError for SortError { impl UError for SortError {
fn code(&self) -> i32 { fn code(&self) -> i32 {
match self { match self {
SortError::Disorder { .. } => 1, Self::Disorder { .. } => 1,
_ => 2, _ => 2,
} }
} }

View file

@ -109,7 +109,7 @@ pub const F_SIGN: u8 = 1 << 4;
// unused at present // unused at present
pub const F_GROUP: u8 = 1 << 5; pub const F_GROUP: u8 = 1 << 5;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum OutputType { pub enum OutputType {
Str, Str,
Integer, Integer,
@ -119,7 +119,7 @@ pub enum OutputType {
Unknown, Unknown,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum Token { pub enum Token {
Char(char), Char(char),
Directive { Directive {

View file

@ -44,17 +44,17 @@ impl Error for TacError {}
impl Display for TacError { impl Display for TacError {
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 {
TacError::InvalidRegex(e) => write!(f, "invalid regular expression: {}", e), Self::InvalidRegex(e) => write!(f, "invalid regular expression: {}", e),
TacError::InvalidArgument(s) => { Self::InvalidArgument(s) => {
write!(f, "{}: read error: Invalid argument", s.maybe_quote()) write!(f, "{}: read error: Invalid argument", s.maybe_quote())
} }
TacError::FileNotFound(s) => write!( Self::FileNotFound(s) => write!(
f, f,
"failed to open {} for reading: No such file or directory", "failed to open {} for reading: No such file or directory",
s.quote() s.quote()
), ),
TacError::ReadError(s, e) => write!(f, "failed to read from {}: {}", s, e), Self::ReadError(s, e) => write!(f, "failed to read from {}: {}", s, e),
TacError::WriteError(e) => write!(f, "failed to write to stdout: {}", e), Self::WriteError(e) => write!(f, "failed to write to stdout: {}", e),
} }
} }
} }

View file

@ -14,7 +14,7 @@ use uucore::display::Quotable;
use uucore::show_error; use uucore::show_error;
/// Represents one of the binary comparison operators for strings, integers, or files /// Represents one of the binary comparison operators for strings, integers, or files
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum Operator { pub enum Operator {
String(OsString), String(OsString),
Int(OsString), Int(OsString),
@ -22,14 +22,14 @@ pub enum Operator {
} }
/// Represents one of the unary test operators for strings or files /// Represents one of the unary test operators for strings or files
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum UnaryOperator { pub enum UnaryOperator {
StrlenOp(OsString), StrlenOp(OsString),
FiletestOp(OsString), FiletestOp(OsString),
} }
/// Represents a parsed token from a test expression /// Represents a parsed token from a test expression
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub enum Symbol { pub enum Symbol {
LParen, LParen,
Bang, Bang,

View file

@ -143,13 +143,13 @@ impl Sequence {
let set1 = Self::from_str(set1_str)?; let set1 = Self::from_str(set1_str)?;
let set2 = Self::from_str(set2_str)?; let set2 = Self::from_str(set2_str)?;
let is_char_star = |s: &&Self| -> bool { matches!(s, Sequence::CharStar(_)) }; let is_char_star = |s: &&Self| -> bool { matches!(s, Self::CharStar(_)) };
let set1_star_count = set1.iter().filter(is_char_star).count(); let set1_star_count = set1.iter().filter(is_char_star).count();
if set1_star_count == 0 { if set1_star_count == 0 {
let set2_star_count = set2.iter().filter(is_char_star).count(); let set2_star_count = set2.iter().filter(is_char_star).count();
if set2_star_count < 2 { if set2_star_count < 2 {
let char_star = set2.iter().find_map(|s| match s { let char_star = set2.iter().find_map(|s| match s {
Sequence::CharStar(c) => Some(c), Self::CharStar(c) => Some(c),
_ => None, _ => None,
}); });
let mut partition = set2.as_slice().split(|s| matches!(s, Self::CharStar(_))); let mut partition = set2.as_slice().split(|s| matches!(s, Self::CharStar(_)));
@ -157,7 +157,7 @@ impl Sequence {
let set2_len = set2 let set2_len = set2
.iter() .iter()
.filter_map(|s| match s { .filter_map(|s| match s {
Sequence::CharStar(_) => None, Self::CharStar(_) => None,
r => Some(r), r => Some(r),
}) })
.flat_map(Self::flatten) .flat_map(Self::flatten)

View file

@ -56,19 +56,19 @@ impl TruncateMode {
/// ``` /// ```
fn to_size(&self, fsize: u64) -> u64 { fn to_size(&self, fsize: u64) -> u64 {
match self { match self {
TruncateMode::Absolute(size) => *size, Self::Absolute(size) => *size,
TruncateMode::Extend(size) => fsize + size, Self::Extend(size) => fsize + size,
TruncateMode::Reduce(size) => { Self::Reduce(size) => {
if *size > fsize { if *size > fsize {
0 0
} else { } else {
fsize - size fsize - size
} }
} }
TruncateMode::AtMost(size) => fsize.min(*size), Self::AtMost(size) => fsize.min(*size),
TruncateMode::AtLeast(size) => fsize.max(*size), Self::AtLeast(size) => fsize.max(*size),
TruncateMode::RoundDown(size) => fsize - fsize % size, Self::RoundDown(size) => fsize - fsize % size,
TruncateMode::RoundUp(size) => fsize + fsize % size, Self::RoundUp(size) => fsize + fsize % size,
} }
} }
} }

View file

@ -147,18 +147,18 @@ impl Input {
/// Converts input to title that appears in stats. /// Converts input to title that appears in stats.
fn to_title(&self, quoting_style: &QuotingStyle) -> Option<String> { fn to_title(&self, quoting_style: &QuotingStyle) -> Option<String> {
match self { match self {
Input::Path(path) => Some(escape_name(&path.clone().into_os_string(), quoting_style)), Self::Path(path) => Some(escape_name(&path.clone().into_os_string(), quoting_style)),
Input::Stdin(StdinKind::Explicit) => { Self::Stdin(StdinKind::Explicit) => {
Some(escape_name(OsStr::new(STDIN_REPR), quoting_style)) Some(escape_name(OsStr::new(STDIN_REPR), quoting_style))
} }
Input::Stdin(StdinKind::Implicit) => None, Self::Stdin(StdinKind::Implicit) => None,
} }
} }
fn path_display(&self, quoting_style: &QuotingStyle) -> String { fn path_display(&self, quoting_style: &QuotingStyle) -> String {
match self { match self {
Input::Path(path) => escape_name(&path.clone().into_os_string(), quoting_style), Self::Path(path) => escape_name(&path.clone().into_os_string(), quoting_style),
Input::Stdin(_) => escape_name(OsStr::new("standard input"), quoting_style), Self::Stdin(_) => escape_name(OsStr::new("standard input"), quoting_style),
} }
} }
} }
@ -172,12 +172,12 @@ enum WcError {
impl UError for WcError { impl UError for WcError {
fn code(&self) -> i32 { fn code(&self) -> i32 {
match self { match self {
WcError::FilesDisabled(_) | WcError::StdinReprNotAllowed(_) => 1, Self::FilesDisabled(_) | Self::StdinReprNotAllowed(_) => 1,
} }
} }
fn usage(&self) -> bool { fn usage(&self) -> bool {
matches!(self, WcError::FilesDisabled(_)) matches!(self, Self::FilesDisabled(_))
} }
} }
@ -186,7 +186,7 @@ impl Error for WcError {}
impl Display for WcError { impl Display for WcError {
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 {
WcError::FilesDisabled(message) | WcError::StdinReprNotAllowed(message) => { Self::FilesDisabled(message) | Self::StdinReprNotAllowed(message) => {
write!(f, "{}", message) write!(f, "{}", message)
} }
} }

View file

@ -29,14 +29,14 @@ use std::os::unix::ffi::OsStrExt;
use std::path::Path; use std::path::Path;
/// The various level of verbosity /// The various level of verbosity
#[derive(PartialEq, Clone, Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub enum VerbosityLevel { pub enum VerbosityLevel {
Silent, Silent,
Changes, Changes,
Verbose, Verbose,
Normal, Normal,
} }
#[derive(PartialEq, Clone, Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub struct Verbosity { pub struct Verbosity {
pub groups_only: bool, pub groups_only: bool,
pub level: VerbosityLevel, pub level: VerbosityLevel,

View file

@ -66,21 +66,21 @@ impl ExitStatus {
pub fn success(&self) -> bool { pub fn success(&self) -> bool {
match *self { match *self {
ExitStatus::Code(code) => code == 0, Self::Code(code) => code == 0,
_ => false, _ => false,
} }
} }
pub fn code(&self) -> Option<i32> { pub fn code(&self) -> Option<i32> {
match *self { match *self {
ExitStatus::Code(code) => Some(code), Self::Code(code) => Some(code),
_ => None, _ => None,
} }
} }
pub fn signal(&self) -> Option<i32> { pub fn signal(&self) -> Option<i32> {
match *self { match *self {
ExitStatus::Signal(code) => Some(code), Self::Signal(code) => Some(code),
_ => None, _ => None,
} }
} }
@ -89,8 +89,8 @@ impl ExitStatus {
impl fmt::Display for ExitStatus { impl fmt::Display for ExitStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
ExitStatus::Code(code) => write!(f, "exit code: {}", code), Self::Code(code) => write!(f, "exit code: {}", code),
ExitStatus::Signal(code) => write!(f, "exit code: {}", code), Self::Signal(code) => write!(f, "exit code: {}", code),
} }
} }
} }

View file

@ -19,7 +19,7 @@ pub struct FormatPrimitive {
pub suffix: Option<String>, pub suffix: Option<String>,
} }
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq, Eq)]
pub enum Base { pub enum Base {
Ten = 10, Ten = 10,
Hex = 16, Hex = 16,

View file

@ -33,7 +33,7 @@ fn warn_char_constant_ign(remaining_bytes: &[u8]) {
show_warning!( show_warning!(
"{:?}: character(s) following character \ "{:?}: character(s) following character \
constant have been ignored", constant have been ignored",
&*remaining_bytes remaining_bytes
); );
} }
} }

View file

@ -148,7 +148,7 @@ pub enum BackupError {
impl UError for BackupError { impl UError for BackupError {
fn code(&self) -> i32 { fn code(&self) -> i32 {
match self { match self {
BackupError::BackupImpossible() => 2, Self::BackupImpossible() => 2,
_ => 1, _ => 1,
} }
} }
@ -157,7 +157,7 @@ impl UError for BackupError {
// Suggested by clippy. // Suggested by clippy.
matches!( matches!(
self, self,
BackupError::InvalidArgument(_, _) | BackupError::AmbiguousArgument(_, _) Self::InvalidArgument(_, _) | Self::AmbiguousArgument(_, _)
) )
} }
} }
@ -166,25 +166,24 @@ impl Error for BackupError {}
impl Display for BackupError { impl Display for BackupError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use BackupError as BE;
match self { match self {
BE::InvalidArgument(arg, origin) => write!( Self::InvalidArgument(arg, origin) => write!(
f, f,
"invalid argument {} for '{}'\n{}", "invalid argument {} for '{}'\n{}",
arg.quote(), arg.quote(),
origin, origin,
VALID_ARGS_HELP VALID_ARGS_HELP
), ),
BE::AmbiguousArgument(arg, origin) => write!( Self::AmbiguousArgument(arg, origin) => write!(
f, f,
"ambiguous argument {} for '{}'\n{}", "ambiguous argument {} for '{}'\n{}",
arg.quote(), arg.quote(),
origin, origin,
VALID_ARGS_HELP VALID_ARGS_HELP
), ),
BE::BackupImpossible() => write!(f, "cannot create backup"), Self::BackupImpossible() => write!(f, "cannot create backup"),
// Placeholder for later // Placeholder for later
// BE::BackupFailed(from, to, e) => Display::fmt( // Self::BackupFailed(from, to, e) => Display::fmt(
// &uio_error!(e, "failed to backup {} to {}", from.quote(), to.quote()), // &uio_error!(e, "failed to backup {} to {}", from.quote(), to.quote()),
// f // f
// ), // ),

View file

@ -94,9 +94,9 @@ pub enum ParseSizeError {
impl Error for ParseSizeError { impl Error for ParseSizeError {
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
ParseSizeError::InvalidSuffix(ref s) => &*s, Self::InvalidSuffix(ref s) => s,
ParseSizeError::ParseFailure(ref s) => &*s, Self::ParseFailure(ref s) => s,
ParseSizeError::SizeTooBig(ref s) => &*s, Self::SizeTooBig(ref s) => s,
} }
} }
} }
@ -104,9 +104,7 @@ impl Error for ParseSizeError {
impl fmt::Display for ParseSizeError { impl fmt::Display for ParseSizeError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let s = match self { let s = match self {
ParseSizeError::InvalidSuffix(s) Self::InvalidSuffix(s) | Self::ParseFailure(s) | Self::SizeTooBig(s) => s,
| ParseSizeError::ParseFailure(s)
| ParseSizeError::SizeTooBig(s) => s,
}; };
write!(f, "{}", s) write!(f, "{}", s)
} }