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
This commit is contained in:
Aarya Khandelwal 2024-03-23 18:18:49 +05:30 committed by GitHub
parent 3c05b58221
commit 566fd475d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 57 additions and 68 deletions

View file

@ -567,5 +567,5 @@ pub fn extract_mime_type(headers: &HyperHeaders) -> Option<Vec<u8>> {
} }
// Step 7, 8 // Step 7, 8
return mime_type.map(|m| format!("{}", m).into_bytes()); mime_type.map(|m| format!("{}", m).into_bytes())
} }

View file

@ -121,7 +121,7 @@ impl History {
}; };
let global_scope = self.window.upcast::<GlobalScope>(); let global_scope = self.window.upcast::<GlobalScope>();
rooted!(in(*GlobalScope::get_cx()) let mut state = UndefinedValue()); 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"); warn!("Error reading structuredclone data");
} }
self.state.set(state.get()); self.state.set(state.get());
@ -270,7 +270,7 @@ impl History {
// Step 11 // Step 11
let global_scope = self.window.upcast::<GlobalScope>(); let global_scope = self.window.upcast::<GlobalScope>();
rooted!(in(*cx) let mut state = UndefinedValue()); 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"); warn!("Error reading structuredclone data");
} }

View file

@ -601,13 +601,13 @@ pub fn get_element_target(subject: &Element) -> Option<DOMString> {
Some(doc) => { Some(doc) => {
let element = doc.upcast::<Element>(); let element = doc.upcast::<Element>();
if element.has_attribute(&local_name!("target")) { 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 { } else {
return None; None
} }
}, },
None => return None, None => None,
}; }
} }
/// <https://html.spec.whatwg.org/multipage/#get-an-element's-noopener> /// <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(), Some(rel) => rel.Value(),
None => return target_is_blank, None => return target_is_blank,
}; };
return link_types.contains("noreferrer") || link_types.contains("noreferrer") ||
link_types.contains("noopener") || 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> /// <https://html.spec.whatwg.org/multipage/#following-hyperlinks-2>

View file

@ -145,7 +145,7 @@ impl VirtualMethods for HTMLBodyElement {
} }
fn bind_to_tree(&self, context: &BindContext) { 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); s.bind_to_tree(context);
} }

View file

@ -229,8 +229,8 @@ impl VirtualMethods for HTMLButtonElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation); self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() { match *attr.local_name() {
&local_name!("disabled") => { local_name!("disabled") => {
let el = self.upcast::<Element>(); let el = self.upcast::<Element>();
match mutation { match mutation {
AttributeMutation::Set(Some(_)) => {}, AttributeMutation::Set(Some(_)) => {},
@ -248,7 +248,7 @@ impl VirtualMethods for HTMLButtonElement {
self.validity_state() self.validity_state()
.perform_validation_and_update(ValidationFlags::all()); .perform_validation_and_update(ValidationFlags::all());
}, },
&local_name!("type") => match mutation { local_name!("type") => match mutation {
AttributeMutation::Set(_) => { AttributeMutation::Set(_) => {
let value = match &**attr.value() { let value = match &**attr.value() {
"reset" => ButtonType::Reset, "reset" => ButtonType::Reset,
@ -263,7 +263,7 @@ impl VirtualMethods for HTMLButtonElement {
self.button_type.set(ButtonType::Submit); self.button_type.set(ButtonType::Submit);
}, },
}, },
&local_name!("form") => { local_name!("form") => {
self.form_attribute_mutated(mutation); self.form_attribute_mutated(mutation);
self.validity_state() self.validity_state()
.perform_validation_and_update(ValidationFlags::empty()); .perform_validation_and_update(ValidationFlags::empty());
@ -273,7 +273,7 @@ impl VirtualMethods for HTMLButtonElement {
} }
fn bind_to_tree(&self, context: &BindContext) { 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); s.bind_to_tree(context);
} }
@ -306,7 +306,7 @@ impl FormControl for HTMLButtonElement {
self.form_owner.set(form); self.form_owner.set(form);
} }
fn to_element<'a>(&'a self) -> &'a Element { fn to_element(&self) -> &Element {
self.upcast::<Element>() self.upcast::<Element>()
} }
} }

View file

@ -179,7 +179,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn get_canvas_id_for_layout(self) -> CanvasId { fn get_canvas_id_for_layout(self) -> CanvasId {
unsafe { unsafe {
let canvas = &*self.unsafe_get(); let canvas = self.unsafe_get();
if let &Some(CanvasContext::Context2d(ref context)) = canvas.context.borrow_for_layout() if let &Some(CanvasContext::Context2d(ref context)) = canvas.context.borrow_for_layout()
{ {
context.to_layout().get_canvas_id() context.to_layout().get_canvas_id()
@ -277,7 +277,7 @@ impl HTMLCanvasElement {
/// Gets the base WebGLRenderingContext for WebGL or WebGL 2, if exists. /// Gets the base WebGLRenderingContext for WebGL or WebGL 2, if exists.
pub fn get_base_webgl_context(&self) -> Option<DomRoot<WebGLRenderingContext>> { pub fn get_base_webgl_context(&self) -> Option<DomRoot<WebGLRenderingContext>> {
match *self.context.borrow() { 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()), Some(CanvasContext::WebGL2(ref context)) => Some(context.base_context()),
_ => None, _ => None,
} }
@ -460,9 +460,9 @@ impl VirtualMethods for HTMLCanvasElement {
} }
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name { match *name {
&local_name!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH), local_name!("width") => AttrValue::from_u32(value.into(), DEFAULT_WIDTH),
&local_name!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT), local_name!("height") => AttrValue::from_u32(value.into(), DEFAULT_HEIGHT),
_ => self _ => self
.super_type() .super_type()
.unwrap() .unwrap()

View file

@ -195,7 +195,7 @@ impl HTMLCollection {
None => elem.local_name() == qualified_name, None => elem.local_name() == qualified_name,
Some(prefix) => { Some(prefix) => {
qualified_name.starts_with(&**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()) qualified_name.ends_with(&**elem.local_name())
}, },
} }
@ -295,7 +295,7 @@ impl HTMLCollection {
.filter(move |element| self.filter.filter(element, &self.root)) .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. // Iterate forwards from the root.
self.elements_iter_after(&self.root) self.elements_iter_after(&self.root)
} }

View file

@ -559,19 +559,11 @@ fn append_text_node_to_fragment(document: &Document, fragment: &DocumentFragment
static DATA_PREFIX: &str = "data-"; static DATA_PREFIX: &str = "data-";
static DATA_HYPHEN_SEPARATOR: char = '\x2d'; 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 { fn to_snake_case(name: DOMString) -> DOMString {
let mut attr_name = String::with_capacity(name.len() + DATA_PREFIX.len()); let mut attr_name = String::with_capacity(name.len() + DATA_PREFIX.len());
attr_name.push_str(DATA_PREFIX); attr_name.push_str(DATA_PREFIX);
for ch in name.chars() { for ch in name.chars() {
if is_ascii_uppercase(ch) { if ch.is_ascii_uppercase() {
attr_name.push(DATA_HYPHEN_SEPARATOR); attr_name.push(DATA_HYPHEN_SEPARATOR);
attr_name.push(ch.to_ascii_lowercase()); attr_name.push(ch.to_ascii_lowercase());
} else { } else {
@ -591,7 +583,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
return None; return None;
} }
let name = &name[5..]; 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 { if has_uppercase {
return None; return None;
} }
@ -601,7 +593,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
//check for hyphen followed by character //check for hyphen followed by character
if curr_char == DATA_HYPHEN_SEPARATOR { if curr_char == DATA_HYPHEN_SEPARATOR {
if let Some(next_char) = name_chars.next() { 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()); result.push(next_char.to_ascii_uppercase());
} else { } else {
result.push(curr_char); result.push(curr_char);
@ -623,7 +615,7 @@ impl HTMLElement {
.chars() .chars()
.skip_while(|&ch| ch != '\u{2d}') .skip_while(|&ch| ch != '\u{2d}')
.nth(1) .nth(1)
.map_or(false, |ch| ch >= 'a' && ch <= 'z') .map_or(false, |ch| ch.is_ascii_lowercase())
{ {
return Err(Error::Syntax); return Err(Error::Syntax);
} }
@ -670,16 +662,16 @@ impl HTMLElement {
// https://html.spec.whatwg.org/multipage/#category-listed // https://html.spec.whatwg.org/multipage/#category-listed
pub fn is_listed_element(&self) -> bool { pub fn is_listed_element(&self) -> bool {
match self.upcast::<Node>().type_id() { 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::HTMLButtonElement |
HTMLElementTypeId::HTMLFieldSetElement | HTMLElementTypeId::HTMLFieldSetElement |
HTMLElementTypeId::HTMLInputElement | HTMLElementTypeId::HTMLInputElement |
HTMLElementTypeId::HTMLObjectElement | HTMLElementTypeId::HTMLObjectElement |
HTMLElementTypeId::HTMLOutputElement | HTMLElementTypeId::HTMLOutputElement |
HTMLElementTypeId::HTMLSelectElement | HTMLElementTypeId::HTMLSelectElement |
HTMLElementTypeId::HTMLTextAreaElement => true, HTMLElementTypeId::HTMLTextAreaElement
_ => false, ),
},
_ => false, _ => false,
} }
} }
@ -851,9 +843,9 @@ impl VirtualMethods for HTMLElement {
} }
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name { match *name {
&local_name!("itemprop") => AttrValue::from_serialized_tokenlist(value.into()), local_name!("itemprop") => AttrValue::from_serialized_tokenlist(value.into()),
&local_name!("itemtype") => AttrValue::from_serialized_tokenlist(value.into()), local_name!("itemtype") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self _ => self
.super_type() .super_type()
.unwrap() .unwrap()

View file

@ -158,8 +158,8 @@ impl VirtualMethods for HTMLFieldSetElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation); self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() { match *attr.local_name() {
&local_name!("disabled") => { local_name!("disabled") => {
let disabled_state = match mutation { let disabled_state = match mutation {
AttributeMutation::Set(None) => true, AttributeMutation::Set(None) => true,
AttributeMutation::Set(Some(_)) => { AttributeMutation::Set(Some(_)) => {
@ -219,7 +219,7 @@ impl VirtualMethods for HTMLFieldSetElement {
} }
el.update_sequentially_focusable_status(); el.update_sequentially_focusable_status();
}, },
&local_name!("form") => { local_name!("form") => {
self.form_attribute_mutated(mutation); self.form_attribute_mutated(mutation);
}, },
_ => {}, _ => {},
@ -236,7 +236,7 @@ impl FormControl for HTMLFieldSetElement {
self.form_owner.set(form); self.form_owner.set(form);
} }
fn to_element<'a>(&'a self) -> &'a Element { fn to_element(&self) -> &Element {
self.upcast::<Element>() self.upcast::<Element>()
} }
} }

View file

@ -92,10 +92,10 @@ impl VirtualMethods for HTMLFontElement {
} }
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name { match *name {
&local_name!("face") => AttrValue::from_atomic(value.into()), local_name!("face") => AttrValue::from_atomic(value.into()),
&local_name!("color") => AttrValue::from_legacy_color(value.into()), local_name!("color") => AttrValue::from_legacy_color(value.into()),
&local_name!("size") => parse_size(&value), local_name!("size") => parse_size(&value),
_ => self _ => self
.super_type() .super_type()
.unwrap() .unwrap()
@ -174,7 +174,7 @@ fn parse_size(mut input: &str) -> AttrValue {
// Step 9 // Step 9
match parse_mode { match parse_mode {
ParseMode::RelativePlus => value = 3 + value, ParseMode::RelativePlus => value += 3,
ParseMode::RelativeMinus => value = 3 - value, ParseMode::RelativeMinus => value = 3 - value,
ParseMode::Absolute => (), ParseMode::Absolute => (),
} }

View file

@ -180,7 +180,7 @@ impl HTMLFormElement {
.iter() .iter()
.filter(|n| HTMLFormElement::filter_for_radio_list(mode, n, name)) .filter(|n| HTMLFormElement::filter_for_radio_list(mode, n, name))
.nth(index as usize) .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 { pub fn count_for_radio_list(&self, mode: RadioListMode, name: &Atom) -> u32 {
@ -441,14 +441,14 @@ impl HTMLFormElementMethods for HTMLFormElement {
past_names_map.insert( past_names_map.insert(
name, name,
( (
Dom::from_ref(&*element_node.downcast::<Element>().unwrap()), Dom::from_ref(element_node.downcast::<Element>().unwrap()),
NoTrace(Instant::now()), NoTrace(Instant::now()),
), ),
); );
// Step 6 // Step 6
return Some(RadioNodeListOrElement::Element(DomRoot::from_ref( 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 { impl SourcedNameSource {
fn is_past(&self) -> bool { fn is_past(&self) -> bool {
match self { matches!(self, SourcedNameSource::Past(..))
SourcedNameSource::Past(..) => true,
_ => false,
}
} }
} }
@ -512,7 +509,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
if let Some(id_atom) = child.get_id() { if let Some(id_atom) = child.get_id() {
let entry = SourcedName { let entry = SourcedName {
name: id_atom, name: id_atom,
element: DomRoot::from_ref(&*child), element: DomRoot::from_ref(child),
source: SourcedNameSource::Id, source: SourcedNameSource::Id,
}; };
sourced_names_vec.push(entry); sourced_names_vec.push(entry);
@ -520,7 +517,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
if let Some(name_atom) = child.get_name() { if let Some(name_atom) = child.get_name() {
let entry = SourcedName { let entry = SourcedName {
name: name_atom, name: name_atom,
element: DomRoot::from_ref(&*child), element: DomRoot::from_ref(child),
source: SourcedNameSource::Name, source: SourcedNameSource::Name,
}; };
sourced_names_vec.push(entry); sourced_names_vec.push(entry);
@ -534,7 +531,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
if let Some(id_atom) = child.get_id() { if let Some(id_atom) = child.get_id() {
let entry = SourcedName { let entry = SourcedName {
name: id_atom, name: id_atom,
element: DomRoot::from_ref(&*child), element: DomRoot::from_ref(child),
source: SourcedNameSource::Id, source: SourcedNameSource::Id,
}; };
sourced_names_vec.push(entry); sourced_names_vec.push(entry);
@ -542,7 +539,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
if let Some(name_atom) = child.get_name() { if let Some(name_atom) = child.get_name() {
let entry = SourcedName { let entry = SourcedName {
name: name_atom, name: name_atom,
element: DomRoot::from_ref(&*child), element: DomRoot::from_ref(child),
source: SourcedNameSource::Name, source: SourcedNameSource::Name,
}; };
sourced_names_vec.push(entry); 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> /// <https://html.spec.whatwg.org/multipage/#dom-form-checkvalidity>