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

maint: use the matches! macro when possible

This commit is contained in:
Michael Debertol 2021-05-28 17:48:48 +02:00
parent 222bd81190
commit 263b122540
9 changed files with 35 additions and 61 deletions

View file

@ -124,12 +124,7 @@ where
// split the file based on patterns // split the file based on patterns
for pattern in patterns.into_iter() { for pattern in patterns.into_iter() {
let pattern_as_str = pattern.to_string(); let pattern_as_str = pattern.to_string();
#[allow(clippy::match_like_matches_macro)] let is_skip = matches!(pattern, patterns::Pattern::SkipToMatch(_, _, _));
let is_skip = if let patterns::Pattern::SkipToMatch(_, _, _) = pattern {
true
} else {
false
};
match pattern { match pattern {
patterns::Pattern::UpToLine(n, ex) => { patterns::Pattern::UpToLine(n, ex) => {
let mut up_to_line = n; let mut up_to_line = n;

View file

@ -63,12 +63,7 @@ impl Token {
} }
} }
fn is_a_close_paren(&self) -> bool { fn is_a_close_paren(&self) -> bool {
#[allow(clippy::match_like_matches_macro)] matches!(*self, Token::ParClose)
// `matches!(...)` macro not stabilized until rust v1.42
match *self {
Token::ParClose => true,
_ => false,
}
} }
} }

View file

@ -264,12 +264,9 @@ impl<'a> ParagraphStream<'a> {
return false; return false;
} }
#[allow(clippy::match_like_matches_macro)] l_slice[..colon_posn]
// `matches!(...)` macro not stabilized until rust v1.42 .chars()
l_slice[..colon_posn].chars().all(|x| match x as usize { .all(|x| !matches!(x as usize, y if !(33..=126).contains(&y)))
y if !(33..=126).contains(&y) => false,
_ => true,
})
} }
} }
} }
@ -541,12 +538,7 @@ impl<'a> WordSplit<'a> {
} }
fn is_punctuation(c: char) -> bool { fn is_punctuation(c: char) -> bool {
#[allow(clippy::match_like_matches_macro)] matches!(c, '!' | '.' | '?')
// `matches!(...)` macro not stabilized until rust v1.42
match c {
'!' | '.' | '?' => true,
_ => false,
}
} }
} }

View file

@ -51,14 +51,23 @@ struct Options {
} }
fn is_custom_binary(program: &str) -> bool { fn is_custom_binary(program: &str) -> bool {
#[allow(clippy::match_like_matches_macro)] matches!(
// `matches!(...)` macro not stabilized until rust v1.42 program,
match program { "md5sum"
"md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" | "sha1sum"
| "sha3sum" | "sha3-224sum" | "sha3-256sum" | "sha3-384sum" | "sha3-512sum" | "sha224sum"
| "shake128sum" | "shake256sum" | "b2sum" => true, | "sha256sum"
_ => false, | "sha384sum"
} | "sha512sum"
| "sha3sum"
| "sha3-224sum"
| "sha3-256sum"
| "sha3-384sum"
| "sha3-512sum"
| "shake128sum"
| "shake256sum"
| "b2sum"
)
} }
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]

View file

@ -85,12 +85,7 @@ fn od_format_type(type_char: FormatType, byte_size: u8) -> Option<FormatterItemI
} }
fn od_argument_with_option(ch: char) -> bool { fn od_argument_with_option(ch: char) -> bool {
#[allow(clippy::match_like_matches_macro)] matches!(ch, 'A' | 'j' | 'N' | 'S' | 'w')
// `matches!(...)` macro not stabilized until rust v1.42
match ch {
'A' | 'j' | 'N' | 'S' | 'w' => true,
_ => false,
}
} }
/// Parses format flags from command line /// Parses format flags from command line

View file

@ -386,13 +386,8 @@ fn prompt(msg: &str) -> bool {
let stdin = stdin(); let stdin = stdin();
let mut stdin = stdin.lock(); let mut stdin = stdin.lock();
#[allow(clippy::match_like_matches_macro)]
// `matches!(...)` macro not stabilized until rust v1.42
match stdin.read_until(b'\n', &mut buf) { match stdin.read_until(b'\n', &mut buf) {
Ok(x) if x > 0 => match buf[0] { Ok(x) if x > 0 => matches!(buf[0], b'y' | b'Y'),
b'y' | b'Y' => true,
_ => false,
},
_ => false, _ => false,
} }
} }

View file

@ -68,10 +68,10 @@ impl NumInfo {
} }
first_char = false; first_char = false;
if parse_settings if matches!(
.thousands_separator parse_settings.thousands_separator,
.map_or(false, |c| c == char) Some(c) if c == char,
{ ) {
continue; continue;
} }

View file

@ -583,11 +583,10 @@ impl FieldSelector {
is_default_selection: from.field == 1 is_default_selection: from.field == 1
&& from.char == 1 && from.char == 1
&& to.is_none() && to.is_none()
// TODO: Once our MinRustV is 1.42 or higher, change this to the matches! macro && !matches!(
&& match settings.mode { settings.mode,
SortMode::Numeric | SortMode::GeneralNumeric | SortMode::HumanNumeric => false, SortMode::Numeric | SortMode::GeneralNumeric | SortMode::HumanNumeric,
_ => true, ),
},
needs_tokens: from.field != 1 || from.char == 0 || to.is_some(), needs_tokens: from.field != 1 || from.char == 0 || to.is_some(),
from, from,
to, to,
@ -650,7 +649,7 @@ impl FieldSelector {
tokens: Option<&[Field]>, tokens: Option<&[Field]>,
position: &KeyPosition, position: &KeyPosition,
) -> Resolution { ) -> Resolution {
if tokens.map_or(false, |fields| fields.len() < position.field) { if matches!(tokens, Some(tokens) if tokens.len() < position.field) {
Resolution::TooHigh Resolution::TooHigh
} else if position.char == 0 { } else if position.char == 0 {
let end = tokens.unwrap()[position.field - 1].end; let end = tokens.unwrap()[position.field - 1].end;

View file

@ -121,13 +121,7 @@ impl Parser {
/// Test if the next token in the stream is a BOOLOP (-a or -o), without /// Test if the next token in the stream is a BOOLOP (-a or -o), without
/// removing the token from the stream. /// removing the token from the stream.
fn peek_is_boolop(&mut self) -> bool { fn peek_is_boolop(&mut self) -> bool {
// TODO: change to `matches!(self.peek(), Symbol::BoolOp(_))` once MSRV is 1.42 matches!(self.peek(), Symbol::BoolOp(_))
// #[allow(clippy::match_like_matches_macro)] // needs MSRV 1.43
if let Symbol::BoolOp(_) = self.peek() {
true
} else {
false
}
} }
/// Parse an expression. /// Parse an expression.