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
for pattern in patterns.into_iter() {
let pattern_as_str = pattern.to_string();
#[allow(clippy::match_like_matches_macro)]
let is_skip = if let patterns::Pattern::SkipToMatch(_, _, _) = pattern {
true
} else {
false
};
let is_skip = matches!(pattern, patterns::Pattern::SkipToMatch(_, _, _));
match pattern {
patterns::Pattern::UpToLine(n, ex) => {
let mut up_to_line = n;

View file

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

View file

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

View file

@ -51,14 +51,23 @@ struct Options {
}
fn is_custom_binary(program: &str) -> bool {
#[allow(clippy::match_like_matches_macro)]
// `matches!(...)` macro not stabilized until rust v1.42
match program {
"md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum"
| "sha3sum" | "sha3-224sum" | "sha3-256sum" | "sha3-384sum" | "sha3-512sum"
| "shake128sum" | "shake256sum" | "b2sum" => true,
_ => false,
}
matches!(
program,
"md5sum"
| "sha1sum"
| "sha224sum"
| "sha256sum"
| "sha384sum"
| "sha512sum"
| "sha3sum"
| "sha3-224sum"
| "sha3-256sum"
| "sha3-384sum"
| "sha3-512sum"
| "shake128sum"
| "shake256sum"
| "b2sum"
)
}
#[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 {
#[allow(clippy::match_like_matches_macro)]
// `matches!(...)` macro not stabilized until rust v1.42
match ch {
'A' | 'j' | 'N' | 'S' | 'w' => true,
_ => false,
}
matches!(ch, 'A' | 'j' | 'N' | 'S' | 'w')
}
/// Parses format flags from command line

View file

@ -386,13 +386,8 @@ fn prompt(msg: &str) -> bool {
let stdin = stdin();
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) {
Ok(x) if x > 0 => match buf[0] {
b'y' | b'Y' => true,
_ => false,
},
Ok(x) if x > 0 => matches!(buf[0], b'y' | b'Y'),
_ => false,
}
}

View file

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

View file

@ -583,11 +583,10 @@ impl FieldSelector {
is_default_selection: from.field == 1
&& from.char == 1
&& to.is_none()
// TODO: Once our MinRustV is 1.42 or higher, change this to the matches! macro
&& match settings.mode {
SortMode::Numeric | SortMode::GeneralNumeric | SortMode::HumanNumeric => false,
_ => true,
},
&& !matches!(
settings.mode,
SortMode::Numeric | SortMode::GeneralNumeric | SortMode::HumanNumeric,
),
needs_tokens: from.field != 1 || from.char == 0 || to.is_some(),
from,
to,
@ -650,7 +649,7 @@ impl FieldSelector {
tokens: Option<&[Field]>,
position: &KeyPosition,
) -> Resolution {
if tokens.map_or(false, |fields| fields.len() < position.field) {
if matches!(tokens, Some(tokens) if tokens.len() < position.field) {
Resolution::TooHigh
} else if position.char == 0 {
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
/// removing the token from the stream.
fn peek_is_boolop(&mut self) -> bool {
// TODO: change to `matches!(self.peek(), Symbol::BoolOp(_))` once MSRV is 1.42
// #[allow(clippy::match_like_matches_macro)] // needs MSRV 1.43
if let Symbol::BoolOp(_) = self.peek() {
true
} else {
false
}
matches!(self.peek(), Symbol::BoolOp(_))
}
/// Parse an expression.