mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #3720 from andrewbaptist/fix_warnings
Update to handle all the latest cargo warnings
This commit is contained in:
commit
e16545723d
41 changed files with 138 additions and 139 deletions
|
@ -62,8 +62,8 @@ enum LineReader {
|
|||
impl LineReader {
|
||||
fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
|
||||
match *self {
|
||||
LineReader::Stdin(ref mut r) => r.read_line(buf),
|
||||
LineReader::FileIn(ref mut r) => r.read_line(buf),
|
||||
Self::Stdin(ref mut r) => r.read_line(buf),
|
||||
Self::FileIn(ref mut r) => r.read_line(buf),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1519,7 +1519,7 @@ fn copy_link(
|
|||
}
|
||||
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.
|
||||
|
|
|
@ -23,11 +23,11 @@ pub enum Pattern {
|
|||
impl ToString for Pattern {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Pattern::UpToLine(n, _) => n.to_string(),
|
||||
Pattern::UpToMatch(regex, 0, _) => format!("/{}/", regex.as_str()),
|
||||
Pattern::UpToMatch(regex, offset, _) => format!("/{}/{:+}", regex.as_str(), offset),
|
||||
Pattern::SkipToMatch(regex, 0, _) => format!("%{}%", regex.as_str()),
|
||||
Pattern::SkipToMatch(regex, offset, _) => format!("%{}%{:+}", regex.as_str(), offset),
|
||||
Self::UpToLine(n, _) => n.to_string(),
|
||||
Self::UpToMatch(regex, 0, _) => format!("/{}/", regex.as_str()),
|
||||
Self::UpToMatch(regex, offset, _) => format!("/{}/{:+}", regex.as_str(), offset),
|
||||
Self::SkipToMatch(regex, 0, _) => format!("%{}%", regex.as_str()),
|
||||
Self::SkipToMatch(regex, offset, _) => format!("%{}%{:+}", regex.as_str(), offset),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ pub(crate) struct IConvFlags {
|
|||
}
|
||||
|
||||
/// Stores all Conv Flags that apply to the output
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct OConvFlags {
|
||||
pub sparse: bool,
|
||||
pub excl: bool,
|
||||
|
@ -52,7 +52,7 @@ pub struct OConvFlags {
|
|||
}
|
||||
|
||||
/// Stores all Flags that apply to the input
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct IFlags {
|
||||
pub cio: bool,
|
||||
pub direct: bool,
|
||||
|
@ -73,7 +73,7 @@ pub struct IFlags {
|
|||
}
|
||||
|
||||
/// Stores all Flags that apply to the output
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct OFlags {
|
||||
pub append: bool,
|
||||
pub cio: bool,
|
||||
|
@ -96,7 +96,7 @@ pub struct OFlags {
|
|||
/// Defaults to Reads(N)
|
||||
/// if iflag=count_bytes
|
||||
/// then becomes Bytes(N)
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum CountType {
|
||||
Reads(u64),
|
||||
Bytes(u64),
|
||||
|
|
|
@ -18,7 +18,7 @@ use uucore::show_warning;
|
|||
pub type Matches = ArgMatches;
|
||||
|
||||
/// Parser Errors describe errors with parser input
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ParseError {
|
||||
MultipleFmtTable,
|
||||
MultipleUCaseLCase,
|
||||
|
|
|
@ -36,7 +36,7 @@ static LONG_HELP: &str = "
|
|||
mod colors;
|
||||
use self::colors::INTERNAL_DB;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum OutputFmt {
|
||||
Shell,
|
||||
CShell,
|
||||
|
|
|
@ -432,15 +432,15 @@ enum DuError {
|
|||
impl Display for DuError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
DuError::InvalidMaxDepthArg(s) => write!(f, "invalid maximum depth {}", s.quote()),
|
||||
DuError::SummarizeDepthConflict(s) => {
|
||||
Self::InvalidMaxDepthArg(s) => write!(f, "invalid maximum depth {}", s.quote()),
|
||||
Self::SummarizeDepthConflict(s) => {
|
||||
write!(
|
||||
f,
|
||||
"summarizing conflicts with --max-depth={}",
|
||||
s.maybe_quote()
|
||||
)
|
||||
}
|
||||
DuError::InvalidTimeStyleArg(s) => write!(
|
||||
Self::InvalidTimeStyleArg(s) => write!(
|
||||
f,
|
||||
"invalid argument {} for 'time style'
|
||||
Valid arguments are:
|
||||
|
@ -451,13 +451,13 @@ Try '{} --help' for more information.",
|
|||
s.quote(),
|
||||
uucore::execution_phrase()
|
||||
),
|
||||
DuError::InvalidTimeArg(s) => write!(
|
||||
Self::InvalidTimeArg(s) => write!(
|
||||
f,
|
||||
"Invalid argument {} for --time.
|
||||
'birth' and 'creation' arguments are not supported on this platform.",
|
||||
s.quote()
|
||||
),
|
||||
DuError::InvalidGlob(s) => write!(f, "Invalid exclude syntax: {}", s),
|
||||
Self::InvalidGlob(s) => write!(f, "Invalid exclude syntax: {}", s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,13 +42,13 @@ impl AstNode {
|
|||
print!("\t",);
|
||||
}
|
||||
match self {
|
||||
AstNode::Leaf { token_idx, value } => println!(
|
||||
Self::Leaf { token_idx, value } => println!(
|
||||
"Leaf( {} ) at #{} ( evaluate -> {:?} )",
|
||||
value,
|
||||
token_idx,
|
||||
self.evaluate()
|
||||
),
|
||||
AstNode::Node {
|
||||
Self::Node {
|
||||
token_idx,
|
||||
op_type,
|
||||
operands,
|
||||
|
@ -157,7 +157,7 @@ impl AstNode {
|
|||
}
|
||||
}
|
||||
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());
|
||||
for operand in operands {
|
||||
let value = operand.evaluate()?;
|
||||
|
|
|
@ -135,7 +135,7 @@ struct PrimeHeap {
|
|||
|
||||
impl PrimeHeap {
|
||||
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))
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -11,7 +11,8 @@ extern crate uucore;
|
|||
|
||||
use std::error::Error;
|
||||
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;
|
||||
use clap::{crate_version, Arg, Command};
|
||||
|
|
|
@ -70,7 +70,7 @@ impl<T: DoubleInt> Montgomery<T> {
|
|||
|
||||
debug_assert!(x < (self.n.as_double_width()) << t_bits);
|
||||
// TODO: optimize
|
||||
let Montgomery { a, n } = self;
|
||||
let Self { a, n } = self;
|
||||
let m = T::from_double_width(x).wrapping_mul(a);
|
||||
let nm = (n.as_double_width()) * (m.as_double_width());
|
||||
let (xnm, overflow) = x.overflowing_add(&nm); // x + n*m
|
||||
|
|
|
@ -40,16 +40,16 @@ impl Line {
|
|||
// when we know that it's a FormatLine, as in the ParagraphStream iterator
|
||||
fn get_formatline(self) -> FileLine {
|
||||
match self {
|
||||
Line::FormatLine(fl) => fl,
|
||||
Line::NoFormatLine(..) => panic!("Found NoFormatLine when expecting FormatLine"),
|
||||
Self::FormatLine(fl) => fl,
|
||||
Self::NoFormatLine(..) => panic!("Found NoFormatLine when expecting FormatLine"),
|
||||
}
|
||||
}
|
||||
|
||||
// when we know that it's a NoFormatLine, as in the ParagraphStream iterator
|
||||
fn get_noformatline(self) -> (String, bool) {
|
||||
match self {
|
||||
Line::NoFormatLine(s, b) => (s, b),
|
||||
Line::FormatLine(..) => panic!("Found FormatLine when expecting NoFormatLine"),
|
||||
Self::NoFormatLine(s, b) => (s, b),
|
||||
Self::FormatLine(..) => panic!("Found FormatLine when expecting NoFormatLine"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
use std::ffi::OsString;
|
||||
use uucore::parse_size::{parse_size, ParseSizeError};
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum ParseError {
|
||||
Syntax,
|
||||
Overflow,
|
||||
|
|
|
@ -73,7 +73,7 @@ enum InstallError {
|
|||
impl UError for InstallError {
|
||||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
InstallError::Unimplemented(_) => 2,
|
||||
Self::Unimplemented(_) => 2,
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
|
@ -87,41 +87,40 @@ impl Error for InstallError {}
|
|||
|
||||
impl Display for InstallError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
use InstallError as IE;
|
||||
match self {
|
||||
IE::Unimplemented(opt) => write!(f, "Unimplemented feature: {}", opt),
|
||||
IE::DirNeedsArg() => {
|
||||
Self::Unimplemented(opt) => write!(f, "Unimplemented feature: {}", opt),
|
||||
Self::DirNeedsArg() => {
|
||||
write!(
|
||||
f,
|
||||
"{} with -d requires at least one argument.",
|
||||
uucore::util_name()
|
||||
)
|
||||
}
|
||||
IE::CreateDirFailed(dir, e) => {
|
||||
Self::CreateDirFailed(dir, e) => {
|
||||
Display::fmt(&uio_error!(e, "failed to create {}", dir.quote()), f)
|
||||
}
|
||||
IE::ChmodFailed(file) => write!(f, "failed to chmod {}", file.quote()),
|
||||
IE::InvalidTarget(target) => write!(
|
||||
Self::ChmodFailed(file) => write!(f, "failed to chmod {}", file.quote()),
|
||||
Self::InvalidTarget(target) => write!(
|
||||
f,
|
||||
"invalid target {}: No such file or directory",
|
||||
target.quote()
|
||||
),
|
||||
IE::TargetDirIsntDir(target) => {
|
||||
Self::TargetDirIsntDir(target) => {
|
||||
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()),
|
||||
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()),
|
||||
f,
|
||||
),
|
||||
IE::StripProgramFailed(msg) => write!(f, "strip program failed: {}", msg),
|
||||
IE::MetadataFailed(e) => Display::fmt(&uio_error!(e, ""), f),
|
||||
IE::NoSuchUser(user) => write!(f, "no such user: {}", user.maybe_quote()),
|
||||
IE::NoSuchGroup(group) => write!(f, "no such group: {}", group.maybe_quote()),
|
||||
IE::OmittingDirectory(dir) => write!(f, "omitting directory {}", dir.quote()),
|
||||
Self::StripProgramFailed(msg) => write!(f, "strip program failed: {}", msg),
|
||||
Self::MetadataFailed(e) => Display::fmt(&uio_error!(e, ""), f),
|
||||
Self::NoSuchUser(user) => write!(f, "no such user: {}", user.maybe_quote()),
|
||||
Self::NoSuchGroup(group) => write!(f, "no such group: {}", group.maybe_quote()),
|
||||
Self::OmittingDirectory(dir) => write!(f, "omitting directory {}", dir.quote()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ impl Error for JoinError {}
|
|||
impl Display for JoinError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
JoinError::IOError(e) => write!(f, "io error: {}", e),
|
||||
JoinError::UnorderedInput(e) => f.write_str(e),
|
||||
Self::IOError(e) => write!(f, "io error: {}", e),
|
||||
Self::UnorderedInput(e) => f.write_str(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,11 +155,11 @@ enum LsError {
|
|||
impl UError for LsError {
|
||||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
LsError::InvalidLineWidth(_) => 2,
|
||||
LsError::IOError(_) => 1,
|
||||
LsError::IOErrorContext(_, _) => 1,
|
||||
LsError::BlockSizeParseError(_) => 1,
|
||||
LsError::AlreadyListedError(_) => 2,
|
||||
Self::InvalidLineWidth(_) => 2,
|
||||
Self::IOError(_) => 1,
|
||||
Self::IOErrorContext(_, _) => 1,
|
||||
Self::BlockSizeParseError(_) => 1,
|
||||
Self::AlreadyListedError(_) => 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,12 +169,12 @@ impl Error for LsError {}
|
|||
impl Display for LsError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
LsError::BlockSizeParseError(s) => {
|
||||
Self::BlockSizeParseError(s) => {
|
||||
write!(f, "invalid --block-size argument {}", s.quote())
|
||||
}
|
||||
LsError::InvalidLineWidth(s) => write!(f, "invalid line width: {}", s.quote()),
|
||||
LsError::IOError(e) => write!(f, "general io error: {}", e),
|
||||
LsError::IOErrorContext(e, p) => {
|
||||
Self::InvalidLineWidth(s) => write!(f, "invalid line width: {}", s.quote()),
|
||||
Self::IOError(e) => write!(f, "general io error: {}", e),
|
||||
Self::IOErrorContext(e, p) => {
|
||||
let error_kind = e.kind();
|
||||
let errno = e.raw_os_error().unwrap_or(1i32);
|
||||
|
||||
|
@ -236,7 +236,7 @@ impl Display for LsError {
|
|||
},
|
||||
}
|
||||
}
|
||||
LsError::AlreadyListedError(path) => {
|
||||
Self::AlreadyListedError(path) => {
|
||||
write!(
|
||||
f,
|
||||
"{}: not listing already-listed directory",
|
||||
|
|
|
@ -22,22 +22,22 @@ impl UError for MvError {}
|
|||
impl Display for MvError {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
MvError::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),
|
||||
MvError::SelfSubdirectory(s) => write!(
|
||||
Self::NoSuchFile(s) => write!(f, "cannot stat {}: No such file or directory", s),
|
||||
Self::SameFile(s, t) => write!(f, "{} and {} are the same file", s, t),
|
||||
Self::SelfSubdirectory(s) => write!(
|
||||
f,
|
||||
"cannot move '{s}' to a subdirectory of itself, '{s}/{s}'",
|
||||
s = s
|
||||
),
|
||||
MvError::DirectoryToNonDirectory(t) => {
|
||||
Self::DirectoryToNonDirectory(t) => {
|
||||
write!(f, "cannot overwrite directory {} with non-directory", t)
|
||||
}
|
||||
MvError::NonDirectoryToDirectory(s, t) => write!(
|
||||
Self::NonDirectoryToDirectory(s, t) => write!(
|
||||
f,
|
||||
"cannot overwrite non-directory {} with directory {}",
|
||||
t, s
|
||||
),
|
||||
MvError::NotADirectory(t) => write!(f, "target {} is not a directory", t),
|
||||
Self::NotADirectory(t) => write!(f, "target {} is not a directory", t),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ impl Display for NohupError {
|
|||
Self::OpenFailed(_, e) => {
|
||||
write!(f, "failed to open {}: {}", NOHUP_OUT.quote(), e)
|
||||
}
|
||||
NohupError::OpenFailed2(_, e1, s, e2) => write!(
|
||||
Self::OpenFailed2(_, e1, s, e2) => write!(
|
||||
f,
|
||||
"failed to open {}: {}\nfailed to open {}: {}",
|
||||
NOHUP_OUT.quote(),
|
||||
|
|
|
@ -19,9 +19,9 @@ pub enum NumfmtError {
|
|||
impl UError for NumfmtError {
|
||||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
NumfmtError::IoError(_) => 1,
|
||||
NumfmtError::IllegalArgument(_) => 1,
|
||||
NumfmtError::FormattingError(_) => 2,
|
||||
Self::IoError(_) => 1,
|
||||
Self::IllegalArgument(_) => 1,
|
||||
Self::FormattingError(_) => 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ impl Error for NumfmtError {}
|
|||
impl Display for NumfmtError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
NumfmtError::IoError(s)
|
||||
| NumfmtError::IllegalArgument(s)
|
||||
| NumfmtError::FormattingError(s) => write!(f, "{}", s),
|
||||
Self::IoError(s) | Self::IllegalArgument(s) | Self::FormattingError(s) => {
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ pub struct DisplayableSuffix(pub Suffix);
|
|||
|
||||
impl fmt::Display for DisplayableSuffix {
|
||||
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 {
|
||||
RawSuffix::K => write!(f, "K"),
|
||||
RawSuffix::M => write!(f, "M"),
|
||||
|
|
|
@ -35,15 +35,15 @@ impl Eq for FormatWriter {}
|
|||
impl fmt::Debug for FormatWriter {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
FormatWriter::IntWriter(ref p) => {
|
||||
Self::IntWriter(ref p) => {
|
||||
f.write_str("IntWriter:")?;
|
||||
fmt::Pointer::fmt(p, f)
|
||||
}
|
||||
FormatWriter::FloatWriter(ref p) => {
|
||||
Self::FloatWriter(ref p) => {
|
||||
f.write_str("FloatWriter:")?;
|
||||
fmt::Pointer::fmt(p, f)
|
||||
}
|
||||
FormatWriter::MultibyteWriter(ref p) => {
|
||||
Self::MultibyteWriter(ref p) => {
|
||||
f.write_str("MultibyteWriter:")?;
|
||||
fmt::Pointer::fmt(&(*p as *const ()), f)
|
||||
}
|
||||
|
|
|
@ -218,8 +218,10 @@ impl OdOptions {
|
|||
"Radix must be one of [d, o, n, x]".to_string(),
|
||||
));
|
||||
} else {
|
||||
let radix: char =
|
||||
*(st.get(0).expect("byte string of length 1 lacks a 0th elem")) as char;
|
||||
let radix: char = *(st
|
||||
.first()
|
||||
.expect("byte string of length 1 lacks a 0th elem"))
|
||||
as char;
|
||||
match radix {
|
||||
'd' => Radix::Decimal,
|
||||
'x' => Radix::Hexadecimal,
|
||||
|
|
|
@ -29,7 +29,7 @@ impl CommandLineOpts for ArgMatches {
|
|||
/// and an optional label. Offset and label are specified in bytes.
|
||||
/// `FileAndOffset` will be only used if an offset is specified,
|
||||
/// but it might be 0.
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum CommandLineInputs {
|
||||
FileNames(Vec<String>),
|
||||
FileAndOffset((String, u64, Option<u64>)),
|
||||
|
|
|
@ -580,7 +580,7 @@ fn build_options(
|
|||
let date_time = Local::now();
|
||||
date_time.format("%b %d %H:%M %Y").to_string()
|
||||
} else {
|
||||
file_last_modified_time(paths.get(0).unwrap())
|
||||
file_last_modified_time(paths.first().unwrap())
|
||||
};
|
||||
|
||||
// +page option is less priority than --pages
|
||||
|
|
|
@ -24,16 +24,16 @@ impl Number {
|
|||
// requires an addition implementation, and we don't want to
|
||||
// implement that here.
|
||||
match self {
|
||||
Number::Int(n) => n.is_zero(),
|
||||
Number::Float(x) => x.is_zero(),
|
||||
Self::Int(n) => n.is_zero(),
|
||||
Self::Float(x) => x.is_zero(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert this number into an `ExtendedBigDecimal`.
|
||||
pub fn into_extended_big_decimal(self) -> ExtendedBigDecimal {
|
||||
match self {
|
||||
Number::Int(n) => ExtendedBigDecimal::from(n),
|
||||
Number::Float(x) => x,
|
||||
Self::Int(n) => ExtendedBigDecimal::from(n),
|
||||
Self::Float(x) => x,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,11 +54,11 @@ impl Number {
|
|||
// If this number is already an integer, it is already
|
||||
// rounded to the nearest integer in the direction of
|
||||
// `other`.
|
||||
Number::Int(num) => num,
|
||||
Self::Int(num) => num,
|
||||
// Otherwise, if this number is a float, we need to decide
|
||||
// whether `other` is larger or smaller than it, and thus
|
||||
// whether to round up or round down, respectively.
|
||||
Number::Float(num) => {
|
||||
Self::Float(num) => {
|
||||
let other: ExtendedBigDecimal = From::from(other.clone());
|
||||
if other > num {
|
||||
num.ceil()
|
||||
|
|
|
@ -17,7 +17,7 @@ use crate::number::Number;
|
|||
use crate::number::PreciseNumber;
|
||||
|
||||
/// An error returned when parsing a number fails.
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ParseNumberError {
|
||||
Float,
|
||||
Nan,
|
||||
|
|
|
@ -483,7 +483,7 @@ fn wipe_file(
|
|||
|
||||
for _ in 0..n_full_arrays {
|
||||
for p in &PATTERNS {
|
||||
pass_sequence.push(PassType::Pattern(*p));
|
||||
pass_sequence.push(PassType::Pattern(p));
|
||||
}
|
||||
}
|
||||
for pattern in PATTERNS.iter().take(remainder) {
|
||||
|
|
|
@ -22,12 +22,12 @@ enum Sign {
|
|||
Positive,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct NumInfo {
|
||||
exponent: i64,
|
||||
sign: Sign,
|
||||
}
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct NumInfoParseSettings {
|
||||
pub accept_si_units: bool,
|
||||
pub thousands_separator: Option<char>,
|
||||
|
|
|
@ -171,7 +171,7 @@ impl Error for SortError {}
|
|||
impl UError for SortError {
|
||||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
SortError::Disorder { .. } => 1,
|
||||
Self::Disorder { .. } => 1,
|
||||
_ => 2,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ pub const F_SIGN: u8 = 1 << 4;
|
|||
// unused at present
|
||||
pub const F_GROUP: u8 = 1 << 5;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum OutputType {
|
||||
Str,
|
||||
Integer,
|
||||
|
@ -119,7 +119,7 @@ pub enum OutputType {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Token {
|
||||
Char(char),
|
||||
Directive {
|
||||
|
|
|
@ -44,17 +44,17 @@ impl Error for TacError {}
|
|||
impl Display for TacError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
TacError::InvalidRegex(e) => write!(f, "invalid regular expression: {}", e),
|
||||
TacError::InvalidArgument(s) => {
|
||||
Self::InvalidRegex(e) => write!(f, "invalid regular expression: {}", e),
|
||||
Self::InvalidArgument(s) => {
|
||||
write!(f, "{}: read error: Invalid argument", s.maybe_quote())
|
||||
}
|
||||
TacError::FileNotFound(s) => write!(
|
||||
Self::FileNotFound(s) => write!(
|
||||
f,
|
||||
"failed to open {} for reading: No such file or directory",
|
||||
s.quote()
|
||||
),
|
||||
TacError::ReadError(s, e) => write!(f, "failed to read from {}: {}", s, e),
|
||||
TacError::WriteError(e) => write!(f, "failed to write to stdout: {}", e),
|
||||
Self::ReadError(s, e) => write!(f, "failed to read from {}: {}", s, e),
|
||||
Self::WriteError(e) => write!(f, "failed to write to stdout: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use uucore::display::Quotable;
|
|||
use uucore::show_error;
|
||||
|
||||
/// Represents one of the binary comparison operators for strings, integers, or files
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Operator {
|
||||
String(OsString),
|
||||
Int(OsString),
|
||||
|
@ -22,14 +22,14 @@ pub enum Operator {
|
|||
}
|
||||
|
||||
/// Represents one of the unary test operators for strings or files
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum UnaryOperator {
|
||||
StrlenOp(OsString),
|
||||
FiletestOp(OsString),
|
||||
}
|
||||
|
||||
/// Represents a parsed token from a test expression
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Symbol {
|
||||
LParen,
|
||||
Bang,
|
||||
|
|
|
@ -143,13 +143,13 @@ impl Sequence {
|
|||
let set1 = Self::from_str(set1_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();
|
||||
if set1_star_count == 0 {
|
||||
let set2_star_count = set2.iter().filter(is_char_star).count();
|
||||
if set2_star_count < 2 {
|
||||
let char_star = set2.iter().find_map(|s| match s {
|
||||
Sequence::CharStar(c) => Some(c),
|
||||
Self::CharStar(c) => Some(c),
|
||||
_ => None,
|
||||
});
|
||||
let mut partition = set2.as_slice().split(|s| matches!(s, Self::CharStar(_)));
|
||||
|
@ -157,7 +157,7 @@ impl Sequence {
|
|||
let set2_len = set2
|
||||
.iter()
|
||||
.filter_map(|s| match s {
|
||||
Sequence::CharStar(_) => None,
|
||||
Self::CharStar(_) => None,
|
||||
r => Some(r),
|
||||
})
|
||||
.flat_map(Self::flatten)
|
||||
|
|
|
@ -56,19 +56,19 @@ impl TruncateMode {
|
|||
/// ```
|
||||
fn to_size(&self, fsize: u64) -> u64 {
|
||||
match self {
|
||||
TruncateMode::Absolute(size) => *size,
|
||||
TruncateMode::Extend(size) => fsize + size,
|
||||
TruncateMode::Reduce(size) => {
|
||||
Self::Absolute(size) => *size,
|
||||
Self::Extend(size) => fsize + size,
|
||||
Self::Reduce(size) => {
|
||||
if *size > fsize {
|
||||
0
|
||||
} else {
|
||||
fsize - size
|
||||
}
|
||||
}
|
||||
TruncateMode::AtMost(size) => fsize.min(*size),
|
||||
TruncateMode::AtLeast(size) => fsize.max(*size),
|
||||
TruncateMode::RoundDown(size) => fsize - fsize % size,
|
||||
TruncateMode::RoundUp(size) => fsize + fsize % size,
|
||||
Self::AtMost(size) => fsize.min(*size),
|
||||
Self::AtLeast(size) => fsize.max(*size),
|
||||
Self::RoundDown(size) => fsize - fsize % size,
|
||||
Self::RoundUp(size) => fsize + fsize % size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,18 +147,18 @@ impl Input {
|
|||
/// Converts input to title that appears in stats.
|
||||
fn to_title(&self, quoting_style: &QuotingStyle) -> Option<String> {
|
||||
match self {
|
||||
Input::Path(path) => Some(escape_name(&path.clone().into_os_string(), quoting_style)),
|
||||
Input::Stdin(StdinKind::Explicit) => {
|
||||
Self::Path(path) => Some(escape_name(&path.clone().into_os_string(), quoting_style)),
|
||||
Self::Stdin(StdinKind::Explicit) => {
|
||||
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 {
|
||||
match self {
|
||||
Input::Path(path) => escape_name(&path.clone().into_os_string(), quoting_style),
|
||||
Input::Stdin(_) => escape_name(OsStr::new("standard input"), quoting_style),
|
||||
Self::Path(path) => escape_name(&path.clone().into_os_string(), quoting_style),
|
||||
Self::Stdin(_) => escape_name(OsStr::new("standard input"), quoting_style),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,12 +172,12 @@ enum WcError {
|
|||
impl UError for WcError {
|
||||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
WcError::FilesDisabled(_) | WcError::StdinReprNotAllowed(_) => 1,
|
||||
Self::FilesDisabled(_) | Self::StdinReprNotAllowed(_) => 1,
|
||||
}
|
||||
}
|
||||
|
||||
fn usage(&self) -> bool {
|
||||
matches!(self, WcError::FilesDisabled(_))
|
||||
matches!(self, Self::FilesDisabled(_))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ impl Error for WcError {}
|
|||
impl Display for WcError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
WcError::FilesDisabled(message) | WcError::StdinReprNotAllowed(message) => {
|
||||
Self::FilesDisabled(message) | Self::StdinReprNotAllowed(message) => {
|
||||
write!(f, "{}", message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,14 +29,14 @@ use std::os::unix::ffi::OsStrExt;
|
|||
use std::path::Path;
|
||||
|
||||
/// The various level of verbosity
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
pub enum VerbosityLevel {
|
||||
Silent,
|
||||
Changes,
|
||||
Verbose,
|
||||
Normal,
|
||||
}
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
pub struct Verbosity {
|
||||
pub groups_only: bool,
|
||||
pub level: VerbosityLevel,
|
||||
|
|
|
@ -66,21 +66,21 @@ impl ExitStatus {
|
|||
|
||||
pub fn success(&self) -> bool {
|
||||
match *self {
|
||||
ExitStatus::Code(code) => code == 0,
|
||||
Self::Code(code) => code == 0,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn code(&self) -> Option<i32> {
|
||||
match *self {
|
||||
ExitStatus::Code(code) => Some(code),
|
||||
Self::Code(code) => Some(code),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn signal(&self) -> Option<i32> {
|
||||
match *self {
|
||||
ExitStatus::Signal(code) => Some(code),
|
||||
Self::Signal(code) => Some(code),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,8 @@ impl ExitStatus {
|
|||
impl fmt::Display for ExitStatus {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ExitStatus::Code(code) => write!(f, "exit code: {}", code),
|
||||
ExitStatus::Signal(code) => write!(f, "exit code: {}", code),
|
||||
Self::Code(code) => write!(f, "exit code: {}", code),
|
||||
Self::Signal(code) => write!(f, "exit code: {}", code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ pub struct FormatPrimitive {
|
|||
pub suffix: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum Base {
|
||||
Ten = 10,
|
||||
Hex = 16,
|
||||
|
|
|
@ -33,7 +33,7 @@ fn warn_char_constant_ign(remaining_bytes: &[u8]) {
|
|||
show_warning!(
|
||||
"{:?}: character(s) following character \
|
||||
constant have been ignored",
|
||||
&*remaining_bytes
|
||||
remaining_bytes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ pub enum BackupError {
|
|||
impl UError for BackupError {
|
||||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
BackupError::BackupImpossible() => 2,
|
||||
Self::BackupImpossible() => 2,
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ impl UError for BackupError {
|
|||
// Suggested by clippy.
|
||||
matches!(
|
||||
self,
|
||||
BackupError::InvalidArgument(_, _) | BackupError::AmbiguousArgument(_, _)
|
||||
Self::InvalidArgument(_, _) | Self::AmbiguousArgument(_, _)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -166,25 +166,24 @@ impl Error for BackupError {}
|
|||
|
||||
impl Display for BackupError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
use BackupError as BE;
|
||||
match self {
|
||||
BE::InvalidArgument(arg, origin) => write!(
|
||||
Self::InvalidArgument(arg, origin) => write!(
|
||||
f,
|
||||
"invalid argument {} for '{}'\n{}",
|
||||
arg.quote(),
|
||||
origin,
|
||||
VALID_ARGS_HELP
|
||||
),
|
||||
BE::AmbiguousArgument(arg, origin) => write!(
|
||||
Self::AmbiguousArgument(arg, origin) => write!(
|
||||
f,
|
||||
"ambiguous argument {} for '{}'\n{}",
|
||||
arg.quote(),
|
||||
origin,
|
||||
VALID_ARGS_HELP
|
||||
),
|
||||
BE::BackupImpossible() => write!(f, "cannot create backup"),
|
||||
Self::BackupImpossible() => write!(f, "cannot create backup"),
|
||||
// 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()),
|
||||
// f
|
||||
// ),
|
||||
|
|
|
@ -94,9 +94,9 @@ pub enum ParseSizeError {
|
|||
impl Error for ParseSizeError {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
ParseSizeError::InvalidSuffix(ref s) => &*s,
|
||||
ParseSizeError::ParseFailure(ref s) => &*s,
|
||||
ParseSizeError::SizeTooBig(ref s) => &*s,
|
||||
Self::InvalidSuffix(ref s) => s,
|
||||
Self::ParseFailure(ref s) => s,
|
||||
Self::SizeTooBig(ref s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,9 +104,7 @@ impl Error for ParseSizeError {
|
|||
impl fmt::Display for ParseSizeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
let s = match self {
|
||||
ParseSizeError::InvalidSuffix(s)
|
||||
| ParseSizeError::ParseFailure(s)
|
||||
| ParseSizeError::SizeTooBig(s) => s,
|
||||
Self::InvalidSuffix(s) | Self::ParseFailure(s) | Self::SizeTooBig(s) => s,
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue