Clippy: Fixed clippy warnings in components/script/dom (#31801)

* fixed clippy warnings in htmlformelement.rs

* Fixed clippy warnings

* Fixed warnings related to matches!

* made changes to compile "test-tidy" successfully
This commit is contained in:
Aarya Khandelwal 2024-03-21 12:44:12 +05:30 committed by GitHub
parent 5c0199b568
commit da3288dd00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 108 additions and 111 deletions

View file

@ -859,7 +859,7 @@ impl HTMLFormElement {
load_data, load_data,
enctype, enctype,
encoding, encoding,
&target_window, target_window,
); );
}, },
// https://html.spec.whatwg.org/multipage/#submit-get-action // https://html.spec.whatwg.org/multipage/#submit-get-action
@ -868,7 +868,7 @@ impl HTMLFormElement {
("data", FormMethod::FormPost) | ("data", FormMethod::FormPost) |
("ftp", _) | ("ftp", _) |
("javascript", _) => { ("javascript", _) => {
self.plan_to_navigate(load_data, &target_window); self.plan_to_navigate(load_data, target_window);
}, },
("mailto", FormMethod::FormPost) => { ("mailto", FormMethod::FormPost) => {
// TODO: Mail as body // TODO: Mail as body
@ -885,7 +885,7 @@ impl HTMLFormElement {
// https://html.spec.whatwg.org/multipage/#submit-mutate-action // https://html.spec.whatwg.org/multipage/#submit-mutate-action
fn mutate_action_url( fn mutate_action_url(
&self, &self,
form_data: &mut Vec<FormDatum>, form_data: &mut [FormDatum],
mut load_data: LoadData, mut load_data: LoadData,
encoding: &'static Encoding, encoding: &'static Encoding,
target: &Window, target: &Window,
@ -1510,7 +1510,7 @@ pub trait FormControl: DomObject {
fn set_form_owner(&self, form: Option<&HTMLFormElement>); fn set_form_owner(&self, form: Option<&HTMLFormElement>);
fn to_element<'a>(&'a self) -> &'a Element; fn to_element(&self) -> &Element;
fn is_listed(&self) -> bool { fn is_listed(&self) -> bool {
true true
@ -1721,11 +1721,11 @@ impl VirtualMethods for HTMLFormElement {
} }
pub trait FormControlElementHelpers { pub trait FormControlElementHelpers {
fn as_maybe_form_control<'a>(&'a self) -> Option<&'a dyn FormControl>; fn as_maybe_form_control(&self) -> Option<&dyn FormControl>;
} }
impl FormControlElementHelpers for Element { impl FormControlElementHelpers for Element {
fn as_maybe_form_control<'a>(&'a self) -> Option<&'a dyn FormControl> { fn as_maybe_form_control(&self) -> Option<&dyn FormControl> {
let node = self.upcast::<Node>(); let node = self.upcast::<Node>();
match node.type_id() { match node.type_id() {
@ -1766,7 +1766,7 @@ impl FormControlElementHelpers for Element {
// https://html.spec.whatwg.org/multipage/#multipart/form-data-encoding-algorithm // https://html.spec.whatwg.org/multipage/#multipart/form-data-encoding-algorithm
pub fn encode_multipart_form_data( pub fn encode_multipart_form_data(
form_data: &mut Vec<FormDatum>, form_data: &mut [FormDatum],
boundary: String, boundary: String,
encoding: &'static Encoding, encoding: &'static Encoding,
) -> Vec<u8> { ) -> Vec<u8> {

View file

@ -87,7 +87,7 @@ impl VirtualMethods for HTMLHeadElement {
Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods) Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
} }
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);
} }
load_script(self); load_script(self);

View file

@ -97,10 +97,10 @@ impl VirtualMethods for HTMLHRElement {
} }
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!("align") => AttrValue::from_dimension(value.into()), local_name!("align") => AttrValue::from_dimension(value.into()),
&local_name!("color") => AttrValue::from_legacy_color(value.into()), local_name!("color") => AttrValue::from_legacy_color(value.into()),
&local_name!("width") => AttrValue::from_dimension(value.into()), local_name!("width") => AttrValue::from_dimension(value.into()),
_ => self _ => self
.super_type() .super_type()
.unwrap() .unwrap()

View file

@ -168,7 +168,7 @@ impl HTMLIFrameElement {
_ => { _ => {
let mut load_blocker = self.load_blocker.borrow_mut(); let mut load_blocker = self.load_blocker.borrow_mut();
*load_blocker = Some(LoadBlocker::new( *load_blocker = Some(LoadBlocker::new(
&*document, &document,
LoadType::Subframe(load_data.url.clone()), LoadType::Subframe(load_data.url.clone()),
)); ));
}, },
@ -320,7 +320,7 @@ impl HTMLIFrameElement {
return; return;
} }
} }
ancestor = a.parent().map(|p| DomRoot::from_ref(p)); ancestor = a.parent().map(DomRoot::from_ref);
} }
let creator_pipeline_id = if url.as_str() == "about:blank" { let creator_pipeline_id = if url.as_str() == "about:blank" {
@ -517,13 +517,13 @@ impl HTMLIFrameElementLayoutMethods for LayoutDom<'_, HTMLIFrameElement> {
#[inline] #[inline]
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn pipeline_id(self) -> Option<PipelineId> { fn pipeline_id(self) -> Option<PipelineId> {
unsafe { (*self.unsafe_get()).pipeline_id.get() } unsafe { (self.unsafe_get()).pipeline_id.get() }
} }
#[inline] #[inline]
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn browsing_context_id(self) -> Option<BrowsingContextId> { fn browsing_context_id(self) -> Option<BrowsingContextId> {
unsafe { (*self.unsafe_get()).browsing_context_id.get() } unsafe { (self.unsafe_get()).browsing_context_id.get() }
} }
fn get_width(self) -> LengthOrPercentageOrAuto { fn get_width(self) -> LengthOrPercentageOrAuto {
@ -578,7 +578,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
fn GetContentWindow(&self) -> Option<DomRoot<WindowProxy>> { fn GetContentWindow(&self) -> Option<DomRoot<WindowProxy>> {
self.browsing_context_id self.browsing_context_id
.get() .get()
.and_then(|browsing_context_id| ScriptThread::find_window_proxy(browsing_context_id)) .and_then(ScriptThread::find_window_proxy)
} }
// https://html.spec.whatwg.org/multipage/#dom-iframe-contentdocument // https://html.spec.whatwg.org/multipage/#dom-iframe-contentdocument
@ -642,8 +642,8 @@ impl VirtualMethods for HTMLIFrameElement {
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!("sandbox") => { local_name!("sandbox") => {
self.sandbox_allowance self.sandbox_allowance
.set(mutation.new_value(attr).map(|value| { .set(mutation.new_value(attr).map(|value| {
let mut modes = SandboxAllowance::ALLOW_NOTHING; let mut modes = SandboxAllowance::ALLOW_NOTHING;
@ -661,7 +661,7 @@ impl VirtualMethods for HTMLIFrameElement {
modes modes
})); }));
}, },
&local_name!("srcdoc") => { local_name!("srcdoc") => {
// https://html.spec.whatwg.org/multipage/#the-iframe-element:the-iframe-element-9 // https://html.spec.whatwg.org/multipage/#the-iframe-element:the-iframe-element-9
// "Whenever an iframe element with a non-null nested browsing context has its // "Whenever an iframe element with a non-null nested browsing context has its
// srcdoc attribute set, changed, or removed, the user agent must process the // srcdoc attribute set, changed, or removed, the user agent must process the
@ -677,7 +677,7 @@ impl VirtualMethods for HTMLIFrameElement {
self.process_the_iframe_attributes(ProcessingMode::NotFirstTime); self.process_the_iframe_attributes(ProcessingMode::NotFirstTime);
} }
}, },
&local_name!("src") => { local_name!("src") => {
// https://html.spec.whatwg.org/multipage/#the-iframe-element // https://html.spec.whatwg.org/multipage/#the-iframe-element
// "Similarly, whenever an iframe element with a non-null nested browsing context // "Similarly, whenever an iframe element with a non-null nested browsing context
// but with no srcdoc attribute specified has its src attribute set, changed, or removed, // but with no srcdoc attribute specified has its src attribute set, changed, or removed,

View file

@ -704,10 +704,10 @@ impl HTMLImageElement {
/// <https://html.spec.whatwg.org/multipage/#normalise-the-source-densities> /// <https://html.spec.whatwg.org/multipage/#normalise-the-source-densities>
fn normalise_source_densities(&self, source_set: &mut SourceSet, width: Option<Length>) { fn normalise_source_densities(&self, source_set: &mut SourceSet, width: Option<Length>) {
// Step 1 // Step 1
let mut source_size = &mut source_set.source_size; let source_size = &mut source_set.source_size;
// Find source_size_length for Step 2.2 // Find source_size_length for Step 2.2
let source_size_length = self.evaluate_source_size_list(&mut source_size, width); let source_size_length = self.evaluate_source_size_list(source_size, width);
// Step 2 // Step 2
for imgsource in &mut source_set.image_sources { for imgsource in &mut source_set.image_sources {
@ -721,7 +721,7 @@ impl HTMLImageElement {
imgsource.descriptor.den = Some(wid as f64 / source_size_length.to_f64_px()); imgsource.descriptor.den = Some(wid as f64 / source_size_length.to_f64_px());
} else { } else {
//Step 2.3 //Step 2.3
imgsource.descriptor.den = Some(1 as f64); imgsource.descriptor.den = Some(1_f64);
} }
} }
} }
@ -947,7 +947,7 @@ impl HTMLImageElement {
.map_or(false, |p| p.is::<HTMLPictureElement>()); .map_or(false, |p| p.is::<HTMLPictureElement>());
if src_set.is_empty() && !is_parent_picture && !src.is_empty() { if src_set.is_empty() && !is_parent_picture && !src.is_empty() {
selected_source = Some(src.clone()); selected_source = Some(src.clone());
pixel_density = Some(1 as f64); pixel_density = Some(1_f64);
}; };
// Step 5 // Step 5
@ -1579,7 +1579,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
match *url { match *url {
Some(ref url) => USVString(url.clone().into_string()), Some(ref url) => USVString(url.clone().into_string()),
None => { None => {
let ref unparsed_url = current_request.source_url; let unparsed_url = &current_request.source_url;
match *unparsed_url { match *unparsed_url {
Some(ref url) => url.clone(), Some(ref url) => url.clone(),
None => USVString("".to_owned()), None => USVString("".to_owned()),
@ -1722,7 +1722,7 @@ impl VirtualMethods for HTMLImageElement {
} }
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);
} }
let document = document_from_node(self); let document = document_from_node(self);
@ -1761,7 +1761,7 @@ impl FormControl for HTMLImageElement {
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

@ -120,24 +120,23 @@ impl InputType {
// slightly differently, with placeholder characters shown rather // slightly differently, with placeholder characters shown rather
// than the underlying value. // than the underlying value.
fn is_textual(&self) -> bool { fn is_textual(&self) -> bool {
match *self { matches!(
*self,
InputType::Color | InputType::Color |
InputType::Date | InputType::Date |
InputType::DatetimeLocal | InputType::DatetimeLocal |
InputType::Email | InputType::Email |
InputType::Hidden | InputType::Hidden |
InputType::Month | InputType::Month |
InputType::Number | InputType::Number |
InputType::Range | InputType::Range |
InputType::Search | InputType::Search |
InputType::Tel | InputType::Tel |
InputType::Text | InputType::Text |
InputType::Time | InputType::Time |
InputType::Url | InputType::Url |
InputType::Week => true, InputType::Week
)
_ => false,
}
} }
fn is_textual_or_password(&self) -> bool { fn is_textual_or_password(&self) -> bool {
@ -428,45 +427,45 @@ impl HTMLInputElement {
} }
fn does_readonly_apply(&self) -> bool { fn does_readonly_apply(&self) -> bool {
match self.input_type() { matches!(
self.input_type(),
InputType::Text | InputType::Text |
InputType::Search | InputType::Search |
InputType::Url | InputType::Url |
InputType::Tel | InputType::Tel |
InputType::Email | InputType::Email |
InputType::Password | InputType::Password |
InputType::Date | InputType::Date |
InputType::Month | InputType::Month |
InputType::Week | InputType::Week |
InputType::Time | InputType::Time |
InputType::DatetimeLocal | InputType::DatetimeLocal |
InputType::Number => true, InputType::Number
_ => false, )
}
} }
fn does_minmaxlength_apply(&self) -> bool { fn does_minmaxlength_apply(&self) -> bool {
match self.input_type() { matches!(
self.input_type(),
InputType::Text | InputType::Text |
InputType::Search | InputType::Search |
InputType::Url | InputType::Url |
InputType::Tel | InputType::Tel |
InputType::Email | InputType::Email |
InputType::Password => true, InputType::Password
_ => false, )
}
} }
fn does_pattern_apply(&self) -> bool { fn does_pattern_apply(&self) -> bool {
match self.input_type() { matches!(
self.input_type(),
InputType::Text | InputType::Text |
InputType::Search | InputType::Search |
InputType::Url | InputType::Url |
InputType::Tel | InputType::Tel |
InputType::Email | InputType::Email |
InputType::Password => true, InputType::Password
_ => false, )
}
} }
fn does_multiple_apply(&self) -> bool { fn does_multiple_apply(&self) -> bool {
@ -476,24 +475,23 @@ impl HTMLInputElement {
// valueAsNumber, step, min, and max all share the same set of // valueAsNumber, step, min, and max all share the same set of
// input types they apply to // input types they apply to
fn does_value_as_number_apply(&self) -> bool { fn does_value_as_number_apply(&self) -> bool {
match self.input_type() { matches!(
self.input_type(),
InputType::Date | InputType::Date |
InputType::Month | InputType::Month |
InputType::Week | InputType::Week |
InputType::Time | InputType::Time |
InputType::DatetimeLocal | InputType::DatetimeLocal |
InputType::Number | InputType::Number |
InputType::Range => true, InputType::Range
_ => false, )
}
} }
fn does_value_as_date_apply(&self) -> bool { fn does_value_as_date_apply(&self) -> bool {
match self.input_type() { matches!(
InputType::Date | InputType::Month | InputType::Week | InputType::Time => true, self.input_type(),
// surprisingly, spec says false for DateTimeLocal! InputType::Date | InputType::Month | InputType::Week | InputType::Time
_ => false, )
}
} }
// https://html.spec.whatwg.org/multipage#concept-input-step // https://html.spec.whatwg.org/multipage#concept-input-step
@ -1102,15 +1100,14 @@ impl<'dom> LayoutHTMLInputElementHelpers<'dom> for LayoutDom<'dom, HTMLInputElem
impl TextControlElement for HTMLInputElement { impl TextControlElement for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#concept-input-apply // https://html.spec.whatwg.org/multipage/#concept-input-apply
fn selection_api_applies(&self) -> bool { fn selection_api_applies(&self) -> bool {
match self.input_type() { matches!(
self.input_type(),
InputType::Text | InputType::Text |
InputType::Search | InputType::Search |
InputType::Url | InputType::Url |
InputType::Tel | InputType::Tel |
InputType::Password => true, InputType::Password
)
_ => false,
}
} }
// https://html.spec.whatwg.org/multipage/#concept-input-apply // https://html.spec.whatwg.org/multipage/#concept-input-apply
@ -2108,21 +2105,21 @@ impl HTMLInputElement {
.filter_map(DomRoot::downcast::<HTMLInputElement>) .filter_map(DomRoot::downcast::<HTMLInputElement>)
.filter(|input| { .filter(|input| {
input.form_owner() == owner && input.form_owner() == owner &&
match input.input_type() { matches!(
input.input_type(),
InputType::Text | InputType::Text |
InputType::Search | InputType::Search |
InputType::Url | InputType::Url |
InputType::Tel | InputType::Tel |
InputType::Email | InputType::Email |
InputType::Password | InputType::Password |
InputType::Date | InputType::Date |
InputType::Month | InputType::Month |
InputType::Week | InputType::Week |
InputType::Time | InputType::Time |
InputType::DatetimeLocal | InputType::DatetimeLocal |
InputType::Number => true, InputType::Number
_ => false, )
}
}); });
if inputs.skip(1).next().is_some() { if inputs.skip(1).next().is_some() {