Fixed some clippy warnings in components (#32107)

* Fixed some clippy warnings in components

* Updated handling of NaN values in comparison

* Updated formatting using ./mach fmt
This commit is contained in:
komuhangi 2024-04-19 11:48:01 +03:00 committed by GitHub
parent f70413baba
commit 007a72fe4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 20 additions and 29 deletions

View file

@ -1043,7 +1043,7 @@ impl FormControl for HTMLElement {
.set_form_owner(form);
}
fn to_element<'a>(&'a self) -> &'a Element {
fn to_element(&self) -> &Element {
debug_assert!(self.is_form_associated_custom_element());
self.as_element()
}

View file

@ -98,10 +98,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
if text.is_empty() {
// FIXME(nox): Would be cool to not allocate a new string if the
// placeholder is single line, but that's an unimportant detail.
self.placeholder()
.replace("\r\n", "\n")
.replace('\r', "\n")
.into()
self.placeholder().replace("\r\n", "\n").replace('\r', "\n")
} else {
text.into()
}

View file

@ -128,10 +128,7 @@ impl MediaFragmentParser {
fn parse_utc_timestamp(&self, input: &str) -> Result<(Option<f64>, Option<f64>), ()> {
if input.ends_with('-') || input.starts_with(',') || !input.contains('-') {
let sec = parse_hms(
NaiveDateTime::parse_from_str(
&input.replace('-', "").replace(',', ""),
"%Y%m%dT%H%M%S%.fZ",
)
NaiveDateTime::parse_from_str(&input.replace(['-', ','], ""), "%Y%m%dT%H%M%S%.fZ")
.map_err(|_| ())?
.time()
.to_string()

View file

@ -719,15 +719,11 @@ impl Node {
other: &Node,
shadow_including: ShadowIncluding,
) -> Option<DomRoot<Node>> {
for ancestor in self.inclusive_ancestors(shadow_including) {
if other
self.inclusive_ancestors(shadow_including).find(|ancestor| {
other
.inclusive_ancestors(shadow_including)
.any(|node| node == ancestor)
{
return Some(ancestor);
}
}
None
.any(|node| node == *ancestor)
})
}
pub fn is_inclusive_ancestor_of(&self, parent: &Node) -> bool {

View file

@ -438,6 +438,6 @@ impl ElementsByNameList {
pub fn item(&self, index: u32) -> Option<DomRoot<Node>> {
self.document
.nth_element_by_name(index, &self.name)
.and_then(|n| Some(DomRoot::from_ref(&*n)))
.map(|n| DomRoot::from_ref(&*n))
}
}

View file

@ -557,9 +557,9 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
fn AddIceCandidate(&self, candidate: &RTCIceCandidateInit, comp: InRealm) -> Rc<Promise> {
let p = Promise::new_in_current_realm(comp);
if candidate.sdpMid.is_none() && candidate.sdpMLineIndex.is_none() {
p.reject_error(Error::Type(format!(
"one of sdpMid and sdpMLineIndex must be set"
)));
p.reject_error(Error::Type(
"one of sdpMid and sdpMLineIndex must be set".to_string(),
));
return p;
}

View file

@ -2953,7 +2953,8 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
if pbo_offset < 0 || pbo_offset as usize > pixel_unpack_buffer.capacity() {
return Ok(self.base.webgl_error(InvalidValue));
self.base.webgl_error(InvalidValue);
return Ok(());
}
let unpacking_alignment = self.base.texture_unpacking_alignment();
@ -4119,7 +4120,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
handle_potential_webgl_error!(
self.base,
program.get_uniform_block_index(block_name),
return constants::INVALID_INDEX
constants::INVALID_INDEX
)
}

View file

@ -406,7 +406,7 @@ impl WebGLExtensions {
.borrow()
.tex_compression_formats
.keys()
.map(|&k| k)
.copied()
.collect()
}

View file

@ -326,7 +326,7 @@ impl WebGLTexture {
},
EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT => {
// NaN is not less than 1., what a time to be alive.
if !(float_value >= 1.) {
if float_value < 1. || !float_value.is_normal() {
return Err(WebGLError::InvalidValue);
}
self.upcast::<WebGLObject>()