Use matches!() for true/false returning match statements (#2176)

This commit is contained in:
Joseph T. Lyons
2020-07-14 20:11:41 -04:00
committed by GitHub
parent 17e6c53b62
commit 0934410b38
11 changed files with 19 additions and 70 deletions

View File

@ -265,13 +265,7 @@ impl ExternalCommand {
..
} => {
let Path { head, .. } = &**path;
match head {
SpannedExpression {
expr: Expression::Variable(Variable::It(_)),
..
} => true,
_ => false,
}
matches!(head, SpannedExpression{expr: Expression::Variable(Variable::It(_)), ..})
}
_ => false,
})
@ -1352,10 +1346,7 @@ impl NamedArguments {
pub fn switch_present(&self, switch: &str) -> bool {
self.named
.get(switch)
.map(|t| match t {
NamedValue::PresentSwitch(_) => true,
_ => false,
})
.map(|t| matches!(t, NamedValue::PresentSwitch(_)))
.unwrap_or(false)
}
}

View File

@ -77,18 +77,12 @@ impl UntaggedValue {
/// Returns true if this value represents boolean true
pub fn is_true(&self) -> bool {
match self {
UntaggedValue::Primitive(Primitive::Boolean(true)) => true,
_ => false,
}
matches!(self, UntaggedValue::Primitive(Primitive::Boolean(true)))
}
/// Returns true if this value represents a table
pub fn is_table(&self) -> bool {
match self {
UntaggedValue::Table(_) => true,
_ => false,
}
matches!(self, UntaggedValue::Table(_))
}
/// Returns true if the value represents something other than Nothing
@ -98,18 +92,12 @@ impl UntaggedValue {
/// Returns true if the value represents Nothing
pub fn is_none(&self) -> bool {
match self {
UntaggedValue::Primitive(Primitive::Nothing) => true,
_ => false,
}
matches!(self, UntaggedValue::Primitive(Primitive::Nothing))
}
/// Returns true if the value represents an error
pub fn is_error(&self) -> bool {
match self {
UntaggedValue::Error(_err) => true,
_ => false,
}
matches!(self, UntaggedValue::Error(_err))
}
/// Expect this value to be an error and return it
@ -341,10 +329,7 @@ impl Value {
/// View the Value as a Primitive value, if possible
pub fn is_primitive(&self) -> bool {
match &self.value {
UntaggedValue::Primitive(_) => true,
_ => false,
}
matches!(&self.value, UntaggedValue::Primitive(_))
}
/// View the Value as unsigned 64-bit, if possible