From a0522f5cbd9e21b3bc3914f00f456a5c976c0bed Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 20 Dec 2022 16:07:37 +0100 Subject: [PATCH] clippy: fix some "unnested or-patterns" warnings --- src/uu/csplit/src/split_name.rs | 44 +++++++++---------- src/uu/dd/src/parseargs.rs | 2 +- src/uu/numfmt/src/options.rs | 4 +- src/uu/od/src/parse_formats.rs | 12 +++-- src/uu/od/src/parse_nrofbytes.rs | 8 ++-- src/uu/sort/src/sort.rs | 4 +- src/uu/tee/src/tee.rs | 4 +- .../num_format/formatters/float_common.rs | 2 +- 8 files changed, 36 insertions(+), 44 deletions(-) diff --git a/src/uu/csplit/src/split_name.rs b/src/uu/csplit/src/split_name.rs index b1f4f1505..bcbdab701 100644 --- a/src/uu/csplit/src/split_name.rs +++ b/src/uu/csplit/src/split_name.rs @@ -81,18 +81,16 @@ impl SplitName { * zero padding */ // decimal - ("0", "d") | ("0", "i") | ("0", "u") => { - Box::new(move |n: usize| -> String { - format!( - "{}{}{:0width$}{}", - prefix, - before, - n, - after, - width = n_digits - ) - }) - } + ("0", "d" | "i" | "u") => Box::new(move |n: usize| -> String { + format!( + "{}{}{:0width$}{}", + prefix, + before, + n, + after, + width = n_digits + ) + }), // octal ("0", "o") => Box::new(move |n: usize| -> String { format!( @@ -168,18 +166,16 @@ impl SplitName { * Left adjusted */ // decimal - ("-", "d") | ("-", "i") | ("-", "u") => { - Box::new(move |n: usize| -> String { - format!( - "{}{}{:<#width$}{}", - prefix, - before, - n, - after, - width = n_digits - ) - }) - } + ("-", "d" | "i" | "u") => Box::new(move |n: usize| -> String { + format!( + "{}{}{:<#width$}{}", + prefix, + before, + n, + after, + width = n_digits + ) + }), // octal ("-", "o") => Box::new(move |n: usize| -> String { format!( diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index 4ae6cf922..657d29e46 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -505,7 +505,7 @@ fn parse_bytes_no_x(full: &str, s: &str) -> Result { let (num, multiplier) = match (s.find('c'), s.rfind('w'), s.rfind('b')) { (None, None, None) => match parser.parse(s) { Ok(n) => (n, 1), - Err(ParseSizeError::InvalidSuffix(_)) | Err(ParseSizeError::ParseFailure(_)) => { + Err(ParseSizeError::InvalidSuffix(_) | ParseSizeError::ParseFailure(_)) => { return Err(ParseError::InvalidNumber(full.to_string())) } Err(ParseSizeError::SizeTooBig(_)) => { diff --git a/src/uu/numfmt/src/options.rs b/src/uu/numfmt/src/options.rs index 40a18ed16..dc2b73925 100644 --- a/src/uu/numfmt/src/options.rs +++ b/src/uu/numfmt/src/options.rs @@ -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 - while matches!(iter.peek(), Some(' ') | Some('\'') | Some('0')) { + while matches!(iter.peek(), Some(' ' | '\'' | '0')) { match iter.next().unwrap() { ' ' => (), '\'' => options.grouping = true, @@ -178,7 +178,7 @@ impl FromStr for FormatOptions { if let Some('.') = iter.peek() { iter.next(); - if matches!(iter.peek(), Some(' ') | Some('+') | Some('-')) { + if matches!(iter.peek(), Some(' ' | '+' | '-')) { return Err(format!("invalid precision in format '{}'", s)); } diff --git a/src/uu/od/src/parse_formats.rs b/src/uu/od/src/parse_formats.rs index f9f473dc8..9614ed9c0 100644 --- a/src/uu/od/src/parse_formats.rs +++ b/src/uu/od/src/parse_formats.rs @@ -55,28 +55,26 @@ fn od_format_type(type_char: FormatType, byte_size: u8) -> Option Some(FORMAT_ITEM_DEC8S), (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::OctalInt, 1) => Some(FORMAT_ITEM_OCT8), (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::UnsignedInt, 1) => Some(FORMAT_ITEM_DEC8U), (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::HexadecimalInt, 1) => Some(FORMAT_ITEM_HEX8), (FormatType::HexadecimalInt, 2) => Some(FORMAT_ITEM_HEX16), - (FormatType::HexadecimalInt, 0) | (FormatType::HexadecimalInt, 4) => { - Some(FORMAT_ITEM_HEX32) - } + (FormatType::HexadecimalInt, 0 | 4) => Some(FORMAT_ITEM_HEX32), (FormatType::HexadecimalInt, 8) => Some(FORMAT_ITEM_HEX64), (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), _ => None, diff --git a/src/uu/od/src/parse_nrofbytes.rs b/src/uu/od/src/parse_nrofbytes.rs index ad00452aa..4c310755b 100644 --- a/src/uu/od/src/parse_nrofbytes.rs +++ b/src/uu/od/src/parse_nrofbytes.rs @@ -20,11 +20,11 @@ pub fn parse_number_of_bytes(s: &str) -> Result { multiply = 512; len -= 1; } - Some('k') | Some('K') => { + Some('k' | 'K') => { multiply = 1024; len -= 1; } - Some('m') | Some('M') => { + Some('m' | 'M') => { multiply = 1024 * 1024; len -= 1; } @@ -50,8 +50,8 @@ pub fn parse_number_of_bytes(s: &str) -> Result { Some('B') if radix != 16 => { len -= 2; multiply = match ends_with.next() { - Some('k') | Some('K') => 1000, - Some('m') | Some('M') => 1000 * 1000, + Some('k' | 'K') => 1000, + Some('m' | 'M') => 1000 * 1000, Some('G') => 1000 * 1000 * 1000, #[cfg(target_pointer_width = "64")] Some('T') => 1000 * 1000 * 1000 * 1000, diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 916c9915b..dc5cfd91e 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -1201,7 +1201,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { matches .get_one::(options::check::CHECK) .map(|s| s.as_str()), - Some(options::check::SILENT) | Some(options::check::QUIET) + Some(options::check::SILENT | options::check::QUIET) ) { settings.check_silent = true; @@ -1695,7 +1695,7 @@ fn get_leading_gen(input: &str) -> Range { let first = char_indices.peek(); - if matches!(first, Some((_, NEGATIVE)) | Some((_, POSITIVE))) { + if matches!(first, Some((_, NEGATIVE) | (_, POSITIVE))) { char_indices.next(); } diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index a1bc6e194..67b16f843 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -233,9 +233,7 @@ fn open( Err(f) => { show_error!("{}: {}", name.maybe_quote(), f); match output_error { - Some(OutputErrorMode::Exit) | Some(OutputErrorMode::ExitNoPipe) => { - return Err(f) - } + Some(OutputErrorMode::Exit | OutputErrorMode::ExitNoPipe) => return Err(f), _ => Box::new(sink()), } } diff --git a/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs b/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs index eed543807..ba8d5f01d 100644 --- a/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs +++ b/src/uucore/src/lib/features/tokenize/num_format/formatters/float_common.rs @@ -67,7 +67,7 @@ impl FloatAnalysis { let mut pos_before_first_nonzero_after_decimal: Option = None; for c in str_it { match c { - e @ '0'..='9' | e @ 'A'..='F' | e @ 'a'..='f' => { + e @ ('0'..='9' | 'A'..='F' | 'a'..='f') => { if !hex_input { match e { '0'..='9' => {}