aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorAarya Khandelwal <119049564+Aaryakhandelwal@users.noreply.github.com>2024-03-23 18:18:49 +0530
committerGitHub <noreply@github.com>2024-03-23 12:48:49 +0000
commit566fd475d92a6e11f70af18171a2f8bf9b80da68 (patch)
treec7787915847562b661c9486d151d213881667013 /components/script/dom
parent3c05b58221a2b5c879d31d355087a905de6494d8 (diff)
downloadservo-566fd475d92a6e11f70af18171a2f8bf9b80da68.tar.gz
servo-566fd475d92a6e11f70af18171a2f8bf9b80da68.zip
Clippy: Fixed some clippy warnings (#31818)
* Fixed clippy warnings * made changes for lowercase characters. * changed is_lowercase() to is_ascii_lowercase() * added std library function `is_ascii_uppercase()` and `is_ascii_lowercase()` * made recommended changes
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/headers.rs2
-rw-r--r--components/script/dom/history.rs4
-rw-r--r--components/script/dom/htmlanchorelement.rs12
-rw-r--r--components/script/dom/htmlbodyelement.rs2
-rwxr-xr-xcomponents/script/dom/htmlbuttonelement.rs12
-rw-r--r--components/script/dom/htmlcanvaselement.rs10
-rw-r--r--components/script/dom/htmlcollection.rs4
-rw-r--r--components/script/dom/htmlelement.rs40
-rw-r--r--components/script/dom/htmlfieldsetelement.rs8
-rw-r--r--components/script/dom/htmlfontelement.rs10
-rw-r--r--components/script/dom/htmlformelement.rs21
11 files changed, 57 insertions, 68 deletions
diff --git a/components/script/dom/headers.rs b/components/script/dom/headers.rs
index 3b966d1551b..8c8746ffbf2 100644
--- a/components/script/dom/headers.rs
+++ b/components/script/dom/headers.rs
@@ -567,5 +567,5 @@ pub fn extract_mime_type(headers: &HyperHeaders) -> Option<Vec<u8>> {
}
// Step 7, 8
- return mime_type.map(|m| format!("{}", m).into_bytes());
+ mime_type.map(|m| format!("{}", m).into_bytes())
}
diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs
index c996cf87ccd..465d4153c3c 100644
--- a/components/script/dom/history.rs
+++ b/components/script/dom/history.rs
@@ -121,7 +121,7 @@ impl History {
};
let global_scope = self.window.upcast::<GlobalScope>();
rooted!(in(*GlobalScope::get_cx()) let mut state = UndefinedValue());
- if let Err(_) = structuredclone::read(global_scope, data, state.handle_mut()) {
+ if structuredclone::read(global_scope, data, state.handle_mut()).is_err() {
warn!("Error reading structuredclone data");
}
self.state.set(state.get());
@@ -270,7 +270,7 @@ impl History {
// Step 11
let global_scope = self.window.upcast::<GlobalScope>();
rooted!(in(*cx) let mut state = UndefinedValue());
- if let Err(_) = structuredclone::read(global_scope, serialized_data, state.handle_mut()) {
+ if structuredclone::read(global_scope, serialized_data, state.handle_mut()).is_err() {
warn!("Error reading structuredclone data");
}
diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs
index 1d720e7b955..e1aad200e55 100644
--- a/components/script/dom/htmlanchorelement.rs
+++ b/components/script/dom/htmlanchorelement.rs
@@ -601,13 +601,13 @@ pub fn get_element_target(subject: &Element) -> Option<DOMString> {
Some(doc) => {
let element = doc.upcast::<Element>();
if element.has_attribute(&local_name!("target")) {
- return Some(element.get_string_attribute(&local_name!("target")));
+ Some(element.get_string_attribute(&local_name!("target")))
} else {
- return None;
+ None
}
},
- None => return None,
- };
+ None => None,
+ }
}
/// <https://html.spec.whatwg.org/multipage/#get-an-element's-noopener>
@@ -625,9 +625,9 @@ pub fn get_element_noopener(subject: &Element, target_attribute_value: Option<DO
Some(rel) => rel.Value(),
None => return target_is_blank,
};
- return link_types.contains("noreferrer") ||
+ link_types.contains("noreferrer") ||
link_types.contains("noopener") ||
- (!link_types.contains("opener") && target_is_blank);
+ (!link_types.contains("opener") && target_is_blank)
}
/// <https://html.spec.whatwg.org/multipage/#following-hyperlinks-2>
diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs
index 64f482f054c..4dcbfe0b80f 100644
--- a/components/script/dom/htmlbodyelement.rs
+++ b/components/script/dom/htmlbodyelement.rs
@@ -145,7 +145,7 @@ impl VirtualMethods for HTMLBodyElement {
}
fn bind_to_tree(&self, context: &BindContext) {
- if let Some(ref s) = self.super_type() {
+ if let Some(s) = self.super_type() {
s.bind_to_tree(context);
}
diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs
index dc6c799005f..a851b1ecc3c 100755
--- a/components/script/dom/htmlbuttonelement.rs
+++ b/components/script/dom/htmlbuttonelement.rs
@@ -229,8 +229,8 @@ impl VirtualMethods for HTMLButtonElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
- match attr.local_name() {
- &local_name!("disabled") => {
+ match *attr.local_name() {
+ local_name!("disabled") => {
let el = self.upcast::<Element>();
match mutation {
AttributeMutation::Set(Some(_)) => {},
@@ -248,7 +248,7 @@ impl VirtualMethods for HTMLButtonElement {
self.validity_state()
.perform_validation_and_update(ValidationFlags::all());
},
- &local_name!("type") => match mutation {
+ local_name!("type") => match mutation {
AttributeMutation::Set(_) => {
let value = match &**attr.value() {
"reset" => ButtonType::Reset,
@@ -263,7 +263,7 @@ impl VirtualMethods for HTMLButtonElement {
self.button_type.set(ButtonType::Submit);
},
},
- &local_name!("form") => {
+ local_name!("form") => {
self.form_attribute_mutated(mutation);
self.validity_state()
.perform_validation_and_update(ValidationFlags::empty());
@@ -273,7 +273,7 @@ impl VirtualMethods for HTMLButtonElement {
}
fn bind_to_tree(&self, context: &BindContext) {
- if let Some(ref s) = self.super_type() {
+ if let Some(s) = self.super_type() {
s.bind_to_tree(context);
}
@@ -306,7 +306,7 @@ impl FormControl for HTMLButtonElement {
self.form_owner.set(form);
}
- fn to_element<'a>(&'a self) -> &'a Element {
+ fn to_element(&self) -> &Element {
self.upcast::<Element>()
}
}
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs
index dce5fd0ea5e..a2b6aa6a2a8 100644
--- a/components/script/dom/htmlcanvaselement.rs
+++ b/components/script/dom/htmlcanvaselement.rs
@@ -179,7 +179,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
#[allow(unsafe_code)]
fn get_canvas_id_for_layout(self) -> CanvasId {
unsafe {
- let canvas = &*self.unsafe_get();
+ let canvas = self.unsafe_get();
if let &Some(CanvasContext::Context2d(ref context)) = canvas.context.borrow_for_layout()
{
context.to_layout().get_canvas_id()
@@ -277,7 +277,7 @@ impl HTMLCanvasElement {
/// Gets the base WebGLRenderingContext for WebGL or WebGL 2, if exists.
pub fn get_base_webgl_context(&self) -> Option<DomRoot<WebGLRenderingContext>> {
match *self.context.borrow() {
- Some(CanvasContext::WebGL(ref context)) => Some(DomRoot::from_ref(&*context)),
+ Some(CanvasContext::WebGL(ref context)) => Some(DomRoot::from_ref(context)),
Some(CanvasContext::WebGL2(ref context)) => Some(context.base_context()),
_ => None,
}
@@ -460,9 +460,9 @@ impl VirtualMethods for HTMLCanvasElement {
}
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
- match name {
- &local_name!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH),
- &local_name!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT),
+ match *name {
+ local_name!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH),
+ local_name!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT),
_ => self
.super_type()
.unwrap()
diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs
index 5a01e5be773..cfcc8b5f2ef 100644
--- a/components/script/dom/htmlcollection.rs
+++ b/components/script/dom/htmlcollection.rs
@@ -195,7 +195,7 @@ impl HTMLCollection {
None => elem.local_name() == qualified_name,
Some(prefix) => {
qualified_name.starts_with(&**prefix) &&
- qualified_name.find(":") == Some(prefix.len()) &&
+ qualified_name.find(':') == Some(prefix.len()) &&
qualified_name.ends_with(&**elem.local_name())
},
}
@@ -295,7 +295,7 @@ impl HTMLCollection {
.filter(move |element| self.filter.filter(element, &self.root))
}
- pub fn elements_iter<'a>(&'a self) -> impl Iterator<Item = DomRoot<Element>> + 'a {
+ pub fn elements_iter(&self) -> impl Iterator<Item = DomRoot<Element>> + '_ {
// Iterate forwards from the root.
self.elements_iter_after(&self.root)
}
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index 8a199ec9b4d..f40c5439de7 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -559,19 +559,11 @@ fn append_text_node_to_fragment(document: &Document, fragment: &DocumentFragment
static DATA_PREFIX: &str = "data-";
static DATA_HYPHEN_SEPARATOR: char = '\x2d';
-fn is_ascii_uppercase(c: char) -> bool {
- 'A' <= c && c <= 'Z'
-}
-
-fn is_ascii_lowercase(c: char) -> bool {
- 'a' <= c && c <= 'w'
-}
-
fn to_snake_case(name: DOMString) -> DOMString {
let mut attr_name = String::with_capacity(name.len() + DATA_PREFIX.len());
attr_name.push_str(DATA_PREFIX);
for ch in name.chars() {
- if is_ascii_uppercase(ch) {
+ if ch.is_ascii_uppercase() {
attr_name.push(DATA_HYPHEN_SEPARATOR);
attr_name.push(ch.to_ascii_lowercase());
} else {
@@ -591,7 +583,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
return None;
}
let name = &name[5..];
- let has_uppercase = name.chars().any(|curr_char| is_ascii_uppercase(curr_char));
+ let has_uppercase = name.chars().any(|curr_char| curr_char.is_ascii_uppercase());
if has_uppercase {
return None;
}
@@ -601,7 +593,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
//check for hyphen followed by character
if curr_char == DATA_HYPHEN_SEPARATOR {
if let Some(next_char) = name_chars.next() {
- if is_ascii_lowercase(next_char) {
+ if next_char.is_ascii_lowercase() {
result.push(next_char.to_ascii_uppercase());
} else {
result.push(curr_char);
@@ -623,7 +615,7 @@ impl HTMLElement {
.chars()
.skip_while(|&ch| ch != '\u{2d}')
.nth(1)
- .map_or(false, |ch| ch >= 'a' && ch <= 'z')
+ .map_or(false, |ch| ch.is_ascii_lowercase())
{
return Err(Error::Syntax);
}
@@ -670,16 +662,16 @@ impl HTMLElement {
// https://html.spec.whatwg.org/multipage/#category-listed
pub fn is_listed_element(&self) -> bool {
match self.upcast::<Node>().type_id() {
- NodeTypeId::Element(ElementTypeId::HTMLElement(type_id)) => match type_id {
+ NodeTypeId::Element(ElementTypeId::HTMLElement(type_id)) => matches!(
+ type_id,
HTMLElementTypeId::HTMLButtonElement |
- HTMLElementTypeId::HTMLFieldSetElement |
- HTMLElementTypeId::HTMLInputElement |
- HTMLElementTypeId::HTMLObjectElement |
- HTMLElementTypeId::HTMLOutputElement |
- HTMLElementTypeId::HTMLSelectElement |
- HTMLElementTypeId::HTMLTextAreaElement => true,
- _ => false,
- },
+ HTMLElementTypeId::HTMLFieldSetElement |
+ HTMLElementTypeId::HTMLInputElement |
+ HTMLElementTypeId::HTMLObjectElement |
+ HTMLElementTypeId::HTMLOutputElement |
+ HTMLElementTypeId::HTMLSelectElement |
+ HTMLElementTypeId::HTMLTextAreaElement
+ ),
_ => false,
}
}
@@ -851,9 +843,9 @@ impl VirtualMethods for HTMLElement {
}
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
- match name {
- &local_name!("itemprop") => AttrValue::from_serialized_tokenlist(value.into()),
- &local_name!("itemtype") => AttrValue::from_serialized_tokenlist(value.into()),
+ match *name {
+ local_name!("itemprop") => AttrValue::from_serialized_tokenlist(value.into()),
+ local_name!("itemtype") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self
.super_type()
.unwrap()
diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs
index b29f4b471b0..f944ccddc92 100644
--- a/components/script/dom/htmlfieldsetelement.rs
+++ b/components/script/dom/htmlfieldsetelement.rs
@@ -158,8 +158,8 @@ impl VirtualMethods for HTMLFieldSetElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
- match attr.local_name() {
- &local_name!("disabled") => {
+ match *attr.local_name() {
+ local_name!("disabled") => {
let disabled_state = match mutation {
AttributeMutation::Set(None) => true,
AttributeMutation::Set(Some(_)) => {
@@ -219,7 +219,7 @@ impl VirtualMethods for HTMLFieldSetElement {
}
el.update_sequentially_focusable_status();
},
- &local_name!("form") => {
+ local_name!("form") => {
self.form_attribute_mutated(mutation);
},
_ => {},
@@ -236,7 +236,7 @@ impl FormControl for HTMLFieldSetElement {
self.form_owner.set(form);
}
- fn to_element<'a>(&'a self) -> &'a Element {
+ fn to_element(&self) -> &Element {
self.upcast::<Element>()
}
}
diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs
index 9bdd32bb5c4..641dd8a92f3 100644
--- a/components/script/dom/htmlfontelement.rs
+++ b/components/script/dom/htmlfontelement.rs
@@ -92,10 +92,10 @@ impl VirtualMethods for HTMLFontElement {
}
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
- match name {
- &local_name!("face") => AttrValue::from_atomic(value.into()),
- &local_name!("color") => AttrValue::from_legacy_color(value.into()),
- &local_name!("size") => parse_size(&value),
+ match *name {
+ local_name!("face") => AttrValue::from_atomic(value.into()),
+ local_name!("color") => AttrValue::from_legacy_color(value.into()),
+ local_name!("size") => parse_size(&value),
_ => self
.super_type()
.unwrap()
@@ -174,7 +174,7 @@ fn parse_size(mut input: &str) -> AttrValue {
// Step 9
match parse_mode {
- ParseMode::RelativePlus => value = 3 + value,
+ ParseMode::RelativePlus => value += 3,
ParseMode::RelativeMinus => value = 3 - value,
ParseMode::Absolute => (),
}
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index a9c5c910ad6..cd7c4411892 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -180,7 +180,7 @@ impl HTMLFormElement {
.iter()
.filter(|n| HTMLFormElement::filter_for_radio_list(mode, n, name))
.nth(index as usize)
- .and_then(|n| Some(DomRoot::from_ref(n.upcast::<Node>())))
+ .map(|n| DomRoot::from_ref(n.upcast::<Node>()))
}
pub fn count_for_radio_list(&self, mode: RadioListMode, name: &Atom) -> u32 {
@@ -441,14 +441,14 @@ impl HTMLFormElementMethods for HTMLFormElement {
past_names_map.insert(
name,
(
- Dom::from_ref(&*element_node.downcast::<Element>().unwrap()),
+ Dom::from_ref(element_node.downcast::<Element>().unwrap()),
NoTrace(Instant::now()),
),
);
// Step 6
return Some(RadioNodeListOrElement::Element(DomRoot::from_ref(
- &*element_node.downcast::<Element>().unwrap(),
+ element_node.downcast::<Element>().unwrap(),
)));
}
@@ -486,10 +486,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
impl SourcedNameSource {
fn is_past(&self) -> bool {
- match self {
- SourcedNameSource::Past(..) => true,
- _ => false,
- }
+ matches!(self, SourcedNameSource::Past(..))
}
}
@@ -512,7 +509,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
if let Some(id_atom) = child.get_id() {
let entry = SourcedName {
name: id_atom,
- element: DomRoot::from_ref(&*child),
+ element: DomRoot::from_ref(child),
source: SourcedNameSource::Id,
};
sourced_names_vec.push(entry);
@@ -520,7 +517,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
if let Some(name_atom) = child.get_name() {
let entry = SourcedName {
name: name_atom,
- element: DomRoot::from_ref(&*child),
+ element: DomRoot::from_ref(child),
source: SourcedNameSource::Name,
};
sourced_names_vec.push(entry);
@@ -534,7 +531,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
if let Some(id_atom) = child.get_id() {
let entry = SourcedName {
name: id_atom,
- element: DomRoot::from_ref(&*child),
+ element: DomRoot::from_ref(child),
source: SourcedNameSource::Id,
};
sourced_names_vec.push(entry);
@@ -542,7 +539,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
if let Some(name_atom) = child.get_name() {
let entry = SourcedName {
name: name_atom,
- element: DomRoot::from_ref(&*child),
+ element: DomRoot::from_ref(child),
source: SourcedNameSource::Name,
};
sourced_names_vec.push(entry);
@@ -612,7 +609,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
}
}
- return names_vec;
+ names_vec
}
/// <https://html.spec.whatwg.org/multipage/#dom-form-checkvalidity>