1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-14 19:16:17 +00:00

clippy: fix some "unnested or-patterns" warnings

This commit is contained in:
Daniel Hofstetter 2022-12-20 16:07:37 +01:00
parent 03710a180e
commit a0522f5cbd
8 changed files with 36 additions and 44 deletions

View file

@ -81,18 +81,16 @@ impl SplitName {
* zero padding * zero padding
*/ */
// decimal // decimal
("0", "d") | ("0", "i") | ("0", "u") => { ("0", "d" | "i" | "u") => Box::new(move |n: usize| -> String {
Box::new(move |n: usize| -> String { format!(
format!( "{}{}{:0width$}{}",
"{}{}{:0width$}{}", prefix,
prefix, before,
before, n,
n, after,
after, width = n_digits
width = n_digits )
) }),
})
}
// octal // octal
("0", "o") => Box::new(move |n: usize| -> String { ("0", "o") => Box::new(move |n: usize| -> String {
format!( format!(
@ -168,18 +166,16 @@ impl SplitName {
* Left adjusted * Left adjusted
*/ */
// decimal // decimal
("-", "d") | ("-", "i") | ("-", "u") => { ("-", "d" | "i" | "u") => Box::new(move |n: usize| -> String {
Box::new(move |n: usize| -> String { format!(
format!( "{}{}{:<#width$}{}",
"{}{}{:<#width$}{}", prefix,
prefix, before,
before, n,
n, after,
after, width = n_digits
width = n_digits )
) }),
})
}
// octal // octal
("-", "o") => Box::new(move |n: usize| -> String { ("-", "o") => Box::new(move |n: usize| -> String {
format!( format!(

View file

@ -505,7 +505,7 @@ fn parse_bytes_no_x(full: &str, s: &str) -> Result<u64, ParseError> {
let (num, multiplier) = match (s.find('c'), s.rfind('w'), s.rfind('b')) { let (num, multiplier) = match (s.find('c'), s.rfind('w'), s.rfind('b')) {
(None, None, None) => match parser.parse(s) { (None, None, None) => match parser.parse(s) {
Ok(n) => (n, 1), Ok(n) => (n, 1),
Err(ParseSizeError::InvalidSuffix(_)) | Err(ParseSizeError::ParseFailure(_)) => { Err(ParseSizeError::InvalidSuffix(_) | ParseSizeError::ParseFailure(_)) => {
return Err(ParseError::InvalidNumber(full.to_string())) return Err(ParseError::InvalidNumber(full.to_string()))
} }
Err(ParseSizeError::SizeTooBig(_)) => { Err(ParseSizeError::SizeTooBig(_)) => {

View file

@ -135,7 +135,7 @@ impl FromStr for FormatOptions {
} }
// GNU numfmt allows to mix the characters " ", "'", and "0" in any way, so we do the same // GNU numfmt allows to mix the characters " ", "'", and "0" in any way, so we do the same
while matches!(iter.peek(), Some(' ') | Some('\'') | Some('0')) { while matches!(iter.peek(), Some(' ' | '\'' | '0')) {
match iter.next().unwrap() { match iter.next().unwrap() {
' ' => (), ' ' => (),
'\'' => options.grouping = true, '\'' => options.grouping = true,
@ -178,7 +178,7 @@ impl FromStr for FormatOptions {
if let Some('.') = iter.peek() { if let Some('.') = iter.peek() {
iter.next(); iter.next();
if matches!(iter.peek(), Some(' ') | Some('+') | Some('-')) { if matches!(iter.peek(), Some(' ' | '+' | '-')) {
return Err(format!("invalid precision in format '{}'", s)); return Err(format!("invalid precision in format '{}'", s));
} }

View file

@ -55,28 +55,26 @@ fn od_format_type(type_char: FormatType, byte_size: u8) -> Option<FormatterItemI
(FormatType::DecimalInt, 1) => Some(FORMAT_ITEM_DEC8S), (FormatType::DecimalInt, 1) => Some(FORMAT_ITEM_DEC8S),
(FormatType::DecimalInt, 2) => Some(FORMAT_ITEM_DEC16S), (FormatType::DecimalInt, 2) => Some(FORMAT_ITEM_DEC16S),
(FormatType::DecimalInt, 0) | (FormatType::DecimalInt, 4) => Some(FORMAT_ITEM_DEC32S), (FormatType::DecimalInt, 0 | 4) => Some(FORMAT_ITEM_DEC32S),
(FormatType::DecimalInt, 8) => Some(FORMAT_ITEM_DEC64S), (FormatType::DecimalInt, 8) => Some(FORMAT_ITEM_DEC64S),
(FormatType::OctalInt, 1) => Some(FORMAT_ITEM_OCT8), (FormatType::OctalInt, 1) => Some(FORMAT_ITEM_OCT8),
(FormatType::OctalInt, 2) => Some(FORMAT_ITEM_OCT16), (FormatType::OctalInt, 2) => Some(FORMAT_ITEM_OCT16),
(FormatType::OctalInt, 0) | (FormatType::OctalInt, 4) => Some(FORMAT_ITEM_OCT32), (FormatType::OctalInt, 0 | 4) => Some(FORMAT_ITEM_OCT32),
(FormatType::OctalInt, 8) => Some(FORMAT_ITEM_OCT64), (FormatType::OctalInt, 8) => Some(FORMAT_ITEM_OCT64),
(FormatType::UnsignedInt, 1) => Some(FORMAT_ITEM_DEC8U), (FormatType::UnsignedInt, 1) => Some(FORMAT_ITEM_DEC8U),
(FormatType::UnsignedInt, 2) => Some(FORMAT_ITEM_DEC16U), (FormatType::UnsignedInt, 2) => Some(FORMAT_ITEM_DEC16U),
(FormatType::UnsignedInt, 0) | (FormatType::UnsignedInt, 4) => Some(FORMAT_ITEM_DEC32U), (FormatType::UnsignedInt, 0 | 4) => Some(FORMAT_ITEM_DEC32U),
(FormatType::UnsignedInt, 8) => Some(FORMAT_ITEM_DEC64U), (FormatType::UnsignedInt, 8) => Some(FORMAT_ITEM_DEC64U),
(FormatType::HexadecimalInt, 1) => Some(FORMAT_ITEM_HEX8), (FormatType::HexadecimalInt, 1) => Some(FORMAT_ITEM_HEX8),
(FormatType::HexadecimalInt, 2) => Some(FORMAT_ITEM_HEX16), (FormatType::HexadecimalInt, 2) => Some(FORMAT_ITEM_HEX16),
(FormatType::HexadecimalInt, 0) | (FormatType::HexadecimalInt, 4) => { (FormatType::HexadecimalInt, 0 | 4) => Some(FORMAT_ITEM_HEX32),
Some(FORMAT_ITEM_HEX32)
}
(FormatType::HexadecimalInt, 8) => Some(FORMAT_ITEM_HEX64), (FormatType::HexadecimalInt, 8) => Some(FORMAT_ITEM_HEX64),
(FormatType::Float, 2) => Some(FORMAT_ITEM_F16), (FormatType::Float, 2) => Some(FORMAT_ITEM_F16),
(FormatType::Float, 0) | (FormatType::Float, 4) => Some(FORMAT_ITEM_F32), (FormatType::Float, 0 | 4) => Some(FORMAT_ITEM_F32),
(FormatType::Float, 8) => Some(FORMAT_ITEM_F64), (FormatType::Float, 8) => Some(FORMAT_ITEM_F64),
_ => None, _ => None,

View file

@ -20,11 +20,11 @@ pub fn parse_number_of_bytes(s: &str) -> Result<u64, ParseSizeError> {
multiply = 512; multiply = 512;
len -= 1; len -= 1;
} }
Some('k') | Some('K') => { Some('k' | 'K') => {
multiply = 1024; multiply = 1024;
len -= 1; len -= 1;
} }
Some('m') | Some('M') => { Some('m' | 'M') => {
multiply = 1024 * 1024; multiply = 1024 * 1024;
len -= 1; len -= 1;
} }
@ -50,8 +50,8 @@ pub fn parse_number_of_bytes(s: &str) -> Result<u64, ParseSizeError> {
Some('B') if radix != 16 => { Some('B') if radix != 16 => {
len -= 2; len -= 2;
multiply = match ends_with.next() { multiply = match ends_with.next() {
Some('k') | Some('K') => 1000, Some('k' | 'K') => 1000,
Some('m') | Some('M') => 1000 * 1000, Some('m' | 'M') => 1000 * 1000,
Some('G') => 1000 * 1000 * 1000, Some('G') => 1000 * 1000 * 1000,
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
Some('T') => 1000 * 1000 * 1000 * 1000, Some('T') => 1000 * 1000 * 1000 * 1000,

View file

@ -1201,7 +1201,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
matches matches
.get_one::<String>(options::check::CHECK) .get_one::<String>(options::check::CHECK)
.map(|s| s.as_str()), .map(|s| s.as_str()),
Some(options::check::SILENT) | Some(options::check::QUIET) Some(options::check::SILENT | options::check::QUIET)
) )
{ {
settings.check_silent = true; settings.check_silent = true;
@ -1695,7 +1695,7 @@ fn get_leading_gen(input: &str) -> Range<usize> {
let first = char_indices.peek(); let first = char_indices.peek();
if matches!(first, Some((_, NEGATIVE)) | Some((_, POSITIVE))) { if matches!(first, Some((_, NEGATIVE) | (_, POSITIVE))) {
char_indices.next(); char_indices.next();
} }

View file

@ -233,9 +233,7 @@ fn open(
Err(f) => { Err(f) => {
show_error!("{}: {}", name.maybe_quote(), f); show_error!("{}: {}", name.maybe_quote(), f);
match output_error { match output_error {
Some(OutputErrorMode::Exit) | Some(OutputErrorMode::ExitNoPipe) => { Some(OutputErrorMode::Exit | OutputErrorMode::ExitNoPipe) => return Err(f),
return Err(f)
}
_ => Box::new(sink()), _ => Box::new(sink()),
} }
} }

View file

@ -67,7 +67,7 @@ impl FloatAnalysis {
let mut pos_before_first_nonzero_after_decimal: Option<usize> = None; let mut pos_before_first_nonzero_after_decimal: Option<usize> = None;
for c in str_it { for c in str_it {
match c { match c {
e @ '0'..='9' | e @ 'A'..='F' | e @ 'a'..='f' => { e @ ('0'..='9' | 'A'..='F' | 'a'..='f') => {
if !hex_input { if !hex_input {
match e { match e {
'0'..='9' => {} '0'..='9' => {}