chore: Use matches! to fix clippy lint

This commit is contained in:
Mike Welsh 2020-07-27 03:29:07 -07:00
parent 938a129a49
commit e5480ee9b2
6 changed files with 38 additions and 106 deletions

View File

@ -103,33 +103,14 @@ unsafe impl<'gc> gc_arena::Collect for Value<'gc> {
impl PartialEq for Value<'_> { impl PartialEq for Value<'_> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
match self { match (self, other) {
Value::Undefined => match other { (Value::Undefined, Value::Undefined) => true,
Value::Undefined => true, (Value::Null, Value::Null) => true,
_ => false, (Value::Bool(a), Value::Bool(b)) => a == b,
}, (Value::Number(a), Value::Number(b)) => (a == b) || (a.is_nan() && b.is_nan()),
Value::Null => match other { (Value::String(a), Value::String(b)) => a == b,
Value::Null => true, (Value::Object(a), Value::Object(b)) => Object::ptr_eq(*a, *b),
_ => false, _ => false,
},
Value::Bool(value) => match other {
Value::Bool(other_value) => value == other_value,
_ => false,
},
Value::Number(value) => match other {
Value::Number(other_value) => {
(value == other_value) || (value.is_nan() && other_value.is_nan())
}
_ => false,
},
Value::String(value) => match other {
Value::String(other_value) => **value == **other_value,
_ => false,
},
Value::Object(value) => match other {
Value::Object(other_value) => Object::ptr_eq(*value, *other_value),
_ => false,
},
} }
} }
} }

View File

@ -74,17 +74,11 @@ impl<'gc> Namespace<'gc> {
} }
pub fn is_any(&self) -> bool { pub fn is_any(&self) -> bool {
match self { matches!(self, Self::Any)
Self::Any => true,
_ => false,
}
} }
pub fn is_private(&self) -> bool { pub fn is_private(&self) -> bool {
match self { matches!(self, Self::Private(_))
Self::Private(_) => true,
_ => false,
}
} }
} }

View File

@ -696,17 +696,17 @@ impl<'gc> ScriptObjectData<'gc> {
} }
pub fn has_own_virtual_getter(&self, name: &QName<'gc>) -> bool { pub fn has_own_virtual_getter(&self, name: &QName<'gc>) -> bool {
match self.values.get(name) { matches!(
Some(Property::Virtual { get: Some(_), .. }) => true, self.values.get(name),
_ => false, Some(Property::Virtual { get: Some(_), .. })
} )
} }
pub fn has_own_virtual_setter(&self, name: &QName<'gc>) -> bool { pub fn has_own_virtual_setter(&self, name: &QName<'gc>) -> bool {
match self.values.get(name) { matches!(
Some(Property::Virtual { set: Some(_), .. }) => true, self.values.get(name),
_ => false, Some(Property::Virtual { set: Some(_), .. })
} )
} }
pub fn proto(&self) -> Option<Object<'gc>> { pub fn proto(&self) -> Option<Object<'gc>> {

View File

@ -107,35 +107,15 @@ impl<'gc> From<Namespace<'gc>> for Value<'gc> {
impl PartialEq for Value<'_> { impl PartialEq for Value<'_> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
match self { match (self, other) {
Value::Undefined => match other { (Value::Undefined, Value::Undefined) => true,
Value::Undefined => true, (Value::Null, Value::Null) => true,
_ => false, (Value::Bool(a), Value::Bool(b)) => a == b,
}, (Value::Number(a), Value::Number(b)) => a == b,
Value::Null => match other { (Value::String(a), Value::String(b)) => a == b,
Value::Null => true, (Value::Object(a), Value::Object(b)) => Object::ptr_eq(*a, *b),
_ => false, (Value::Namespace(a), Value::Namespace(b)) => a == b,
}, _ => false,
Value::Bool(value) => match other {
Value::Bool(other_value) => value == other_value,
_ => false,
},
Value::Number(value) => match other {
Value::Number(other_value) => value == other_value,
_ => false,
},
Value::String(value) => match other {
Value::String(other_value) => value == other_value,
_ => false,
},
Value::Object(value) => match other {
Value::Object(other_value) => Object::ptr_eq(*value, *other_value),
_ => false,
},
Value::Namespace(ns) => match other {
Value::Namespace(other_ns) => ns == other_ns,
_ => false,
},
} }
} }
} }

View File

@ -2269,11 +2269,7 @@ impl<'gc, 'a> MovieClip<'gc> {
id, id,
place_object.depth.into(), place_object.depth.into(),
&place_object, &place_object,
if let PlaceObjectAction::Replace(_) = place_object.action { matches!(place_object.action, PlaceObjectAction::Replace(_)),
true
} else {
false
},
) { ) {
child child
} else { } else {
@ -2481,11 +2477,10 @@ impl GotoPlaceObject {
#[inline] #[inline]
fn modifies_original_item(&self) -> bool { fn modifies_original_item(&self) -> bool {
if let swf::PlaceObjectAction::Replace(_) = &self.place_object.action { matches!(
true &self.place_object.action,
} else { swf::PlaceObjectAction::Replace(_)
false )
}
} }
#[inline] #[inline]

View File

@ -793,10 +793,7 @@ impl<'gc> XMLNode<'gc> {
/// Document roots and elements can yield children, while all other /// Document roots and elements can yield children, while all other
/// elements are structurally prohibited from adopting child `XMLNode`s. /// elements are structurally prohibited from adopting child `XMLNode`s.
pub fn has_children(self) -> bool { pub fn has_children(self) -> bool {
match &*self.0.read() { matches!(*self.0.read(), XMLNodeData::Element { .. } | XMLNodeData::DocumentRoot { .. })
XMLNodeData::Element { .. } | XMLNodeData::DocumentRoot { .. } => true,
_ => false,
}
} }
/// Returns an iterator that yields child nodes. /// Returns an iterator that yields child nodes.
@ -937,43 +934,28 @@ impl<'gc> XMLNode<'gc> {
/// Check if this XML node constitutes the root of a whole document. /// Check if this XML node constitutes the root of a whole document.
pub fn is_document_root(self) -> bool { pub fn is_document_root(self) -> bool {
match &*self.0.read() { matches!(*self.0.read(), XMLNodeData::DocumentRoot { .. })
XMLNodeData::DocumentRoot { .. } => true,
_ => false,
}
} }
/// Check if this XML node constitutes an element. /// Check if this XML node constitutes an element.
pub fn is_element(self) -> bool { pub fn is_element(self) -> bool {
match &*self.0.read() { matches!(*self.0.read(), XMLNodeData::Element { .. })
XMLNodeData::Element { .. } => true,
_ => false,
}
} }
/// Check if this XML node constitutes text. /// Check if this XML node constitutes text.
pub fn is_text(self) -> bool { pub fn is_text(self) -> bool {
match &*self.0.read() { matches!(*self.0.read(), XMLNodeData::Text { .. })
XMLNodeData::Text { .. } => true,
_ => false,
}
} }
/// Check if this XML node constitutes text. /// Check if this XML node constitutes text.
#[allow(dead_code)] #[allow(dead_code)]
pub fn is_comment(self) -> bool { pub fn is_comment(self) -> bool {
match &*self.0.read() { matches!(*self.0.read(), XMLNodeData::Comment { .. })
XMLNodeData::Comment { .. } => true,
_ => false,
}
} }
/// Check if this XML node constitutes a DOCTYPE declaration /// Check if this XML node constitutes a DOCTYPE declaration
pub fn is_doctype(self) -> bool { pub fn is_doctype(self) -> bool {
match &*self.0.read() { matches!(*self.0.read(), XMLNodeData::DocType { .. })
XMLNodeData::DocType { .. } => true,
_ => false,
}
} }
/// Create a duplicate copy of this node. /// Create a duplicate copy of this node.