Updated fixes to some clippy warnings in components/script

This commit is contained in:
jahielkomu 2024-03-31 17:19:04 +03:00
parent e74a03724f
commit 2a37c3dec8
58 changed files with 156 additions and 265 deletions

View file

@ -345,16 +345,17 @@ impl Element {
self.is.borrow().clone()
}
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
pub fn set_custom_element_state(&self, state: CustomElementState) {
// no need to inflate rare data for uncustomized
if state != CustomElementState::Uncustomized || self.rare_data().is_some() {
self.ensure_rare_data().custom_element_state = state;
}
// https://dom.spec.whatwg.org/#concept-element-defined
let in_defined_state = match state {
CustomElementState::Uncustomized | CustomElementState::Custom => true,
_ => false,
};
let in_defined_state = matches!(
state,
CustomElementState::Uncustomized | CustomElementState::Custom
);
self.set_state(ElementState::DEFINED, in_defined_state)
}
@ -627,7 +628,7 @@ pub trait LayoutElementHelpers<'dom> {
fn get_lang_for_layout(self) -> String;
fn get_state_for_layout(self) -> ElementState;
fn insert_selector_flags(self, flags: ElementSelectorFlags);
fn has_selector_flags(self, flags: ElementSelectorFlags) -> bool;
fn get_selector_flags(self) -> ElementSelectorFlags;
/// The shadow root this element is a host of.
fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
fn get_attr_for_layout(
@ -707,7 +708,7 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
};
if let Some(color) = bgcolor {
use cssparser::FromParsedColor;
use style::color::parsing::FromParsedColor;
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::BackgroundColor(specified::Color::from_rgba(
@ -747,7 +748,7 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
};
if let Some(color) = color {
use cssparser::FromParsedColor;
use style::color::parsing::FromParsedColor;
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::Color(longhands::color::SpecifiedValue(
@ -1107,8 +1108,8 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
#[inline]
#[allow(unsafe_code)]
fn has_selector_flags(self, flags: ElementSelectorFlags) -> bool {
unsafe { (self.unsafe_get()).selector_flags.get().contains(flags) }
fn get_selector_flags(self) -> ElementSelectorFlags {
unsafe { self.unsafe_get().selector_flags.get() }
}
#[inline]
@ -1393,21 +1394,18 @@ impl Element {
}
// <a>, <input>, <select>, and <textrea> are inherently focusable.
match node.type_id() {
matches!(
node.type_id(),
NodeTypeId::Element(ElementTypeId::HTMLElement(
HTMLElementTypeId::HTMLAnchorElement,
)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(
)) | NodeTypeId::Element(ElementTypeId::HTMLElement(
HTMLElementTypeId::HTMLInputElement,
)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(
)) | NodeTypeId::Element(ElementTypeId::HTMLElement(
HTMLElementTypeId::HTMLSelectElement,
)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(
)) | NodeTypeId::Element(ElementTypeId::HTMLElement(
HTMLElementTypeId::HTMLTextAreaElement,
)) => true,
_ => false,
}
))
)
}
pub fn is_actually_disabled(&self) -> bool {
@ -1493,7 +1491,7 @@ impl Element {
.map(|js| DomRoot::from_ref(&**js))
}
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
/// <https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name>
pub fn get_attribute_by_name(&self, name: DOMString) -> Option<DomRoot<Attr>> {
let name = &self.parsed_name(name);
let maybe_attribute = self
@ -1506,10 +1504,7 @@ impl Element {
if *name == local_name!("id") || *name == local_name!("name") {
match maybe_attr {
None => true,
Some(ref attr) => match *attr.value() {
AttrValue::Atom(_) => true,
_ => false,
},
Some(ref attr) => matches!(*attr.value(), AttrValue::Atom(_)),
}
} else {
true
@ -2932,10 +2927,7 @@ impl VirtualMethods for Element {
//
// Juggle a bit to keep the borrow checker happy
// while avoiding the extra clone.
let is_declaration = match *attr.value() {
AttrValue::Declaration(..) => true,
_ => false,
};
let is_declaration = matches!(*attr.value(), AttrValue::Declaration(..));
let block = if is_declaration {
let mut value = AttrValue::String(String::new());