chore: clippy

This commit is contained in:
Adrian Wielgosik 2021-12-04 22:45:47 +01:00 committed by Adrian Wielgosik
parent 1311b0a3d0
commit 1f5979f168
5 changed files with 29 additions and 34 deletions

View File

@ -589,7 +589,7 @@ pub trait TObject<'gc>: 'gc + Collect + Debug + Into<Object<'gc>> + Clone + Copy
let new_slot_id = self
.vtable()
.unwrap()
.install_const_trait_late(mc, name, value.clone());
.install_const_trait_late(mc, name, value);
self.base_mut(mc)
.install_const_slot_late(new_slot_id, value);
}

View File

@ -154,12 +154,10 @@ impl<'gc> ScriptObjectData<'gc> {
let value = self.values.get(&local_name);
if let Some(value) = value {
return Ok(value.clone());
} else {
if let Some(proto) = self.proto() {
return Ok(*value);
} else if let Some(proto) = self.proto() {
return proto.get_property_local(multiname, activation);
}
}
// Special case: Unresolvable properties on dynamic classes are treated
// as dynamic properties that have not yet been set, and yield
@ -169,9 +167,9 @@ impl<'gc> ScriptObjectData<'gc> {
.map(|cls| cls.inner_class_definition().read().is_sealed())
.unwrap_or(false)
{
return Err(format!("Cannot get undefined property {:?}", local_name).into());
Err(format!("Cannot get undefined property {:?}", local_name).into())
} else {
return Ok(Value::Undefined);
Ok(Value::Undefined)
}
}
@ -277,7 +275,7 @@ impl<'gc> ScriptObjectData<'gc> {
let default_slots = vtable.default_slots();
for value in default_slots.deref() {
if let Some(value) = value {
self.slots.push(value.clone());
self.slots.push(*value);
} else {
self.slots.push(Value::Undefined)
}

View File

@ -74,7 +74,7 @@ impl<'gc, V> PropertyMap<'gc, V> {
.iter()
.filter_map(|v| {
v.iter()
.filter(|(n, _)| name.namespace_set().find(|ns| *ns == n).is_some())
.filter(|(n, _)| name.namespace_set().any(|ns| *ns == *n))
.map(|(_, v)| v)
.next()
})

View File

@ -117,6 +117,7 @@ impl<'gc> ScopeChain<'gc> {
self.domain
}
#[allow(clippy::collapsible_if)]
pub fn find(
&self,
multiname: &Multiname<'gc>,
@ -134,15 +135,13 @@ impl<'gc> ScopeChain<'gc> {
// But no matter what, we always search traits first.
if values.has_trait(multiname) {
return Ok(Some(values));
} else {
if scope.with() || depth == 0 {
} else if scope.with() || depth == 0 {
if values.has_own_property(multiname) {
return Ok(Some(values));
}
}
}
}
}
// That didn't work... let's try searching the domain now.
if let Some((_qname, mut script)) = self.domain.get_defining_script(multiname)? {
return Ok(Some(script.globals(&mut activation.context)?));
@ -198,6 +197,7 @@ impl<'gc> ScopeStack<'gc> {
/// The `global` parameter indicates whether we are on global$init (script initializer).
/// When the `global` parameter is true, the scope at depth 0 is considered the global scope, and is
/// searched for dynamic properties.
#[allow(clippy::collapsible_if)]
pub fn find(
&self,
multiname: &Multiname<'gc>,
@ -208,17 +208,15 @@ impl<'gc> ScopeStack<'gc> {
if values.has_trait(multiname) {
return Ok(Some(values));
} else {
} else if scope.with() || (global && depth == 0) {
// We search the dynamic properties if either conditions are met:
// 1. Scope is a `with` scope
// 2. We are at depth 0 AND we are at global$init (script initializer).
if scope.with() || (global && depth == 0) {
if values.has_own_property(multiname) {
return Ok(Some(values));
}
}
}
}
Ok(None)
}
}

View File

@ -86,6 +86,7 @@ impl<'gc> VTable<'gc> {
///
/// This should be run during the class finalization step, before instances
/// are linked (as instances will further add traits to the list).
#[allow(clippy::if_same_then_else)]
pub fn init_vtable(
self,
defining_class: Option<ClassObject<'gc>>,
@ -231,14 +232,13 @@ impl<'gc> VTable<'gc> {
| TraitKind::Class { slot_id, .. } => {
let slot_id = *slot_id;
let value = trait_to_default_value(scope, &trait_data, activation);
let value = trait_to_default_value(scope, trait_data, activation);
let value = Some(value);
let new_slot_id = if slot_id == 0 {
default_slots.push(value);
default_slots.len() as u32 - 1
} else {
if let Some(Some(_)) = default_slots.get(slot_id as usize) {
} else if let Some(Some(_)) = default_slots.get(slot_id as usize) {
// slot_id conflict
default_slots.push(value);
default_slots.len() as u32 - 1
@ -248,8 +248,7 @@ impl<'gc> VTable<'gc> {
}
default_slots[slot_id as usize] = value;
slot_id
}
} as u32;
};
let new_prop = match trait_data.kind() {
TraitKind::Slot { .. } | TraitKind::Function { .. } => {
@ -343,8 +342,8 @@ fn trait_to_default_value<'gc>(
activation: &mut Activation<'_, 'gc, '_>,
) -> Value<'gc> {
match trait_data.kind() {
TraitKind::Slot { default_value, .. } => default_value.clone(),
TraitKind::Const { default_value, .. } => default_value.clone(),
TraitKind::Slot { default_value, .. } => *default_value,
TraitKind::Const { default_value, .. } => *default_value,
TraitKind::Function { function, .. } => {
FunctionObject::from_function(activation, function.clone(), scope)
.unwrap()