clippy: Fix single_match warnings (#31876)

This commit is contained in:
Oluwatobi Sofela 2024-03-26 15:01:10 +01:00 committed by GitHub
parent d16f259e1d
commit b71de92569
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 115 additions and 133 deletions

View file

@ -354,11 +354,10 @@ impl AudioNodeMethods for AudioNode {
return Ok(());
}
match self.upcast::<EventTarget>().type_id() {
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelSplitterNode) => {
return Err(Error::InvalidState);
},
_ => (),
if let EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelSplitterNode) =
self.upcast::<EventTarget>().type_id()
{
return Err(Error::InvalidState);
};
self.channel_interpretation.set(value);

View file

@ -741,13 +741,10 @@ fn parse_time_component(value: &str) -> Option<(u32, u32, f64)> {
if second_iterator.next()?.len() != 2 {
return None;
}
match second_iterator.next() {
Some(second_last) => {
if second_last.len() > 3 {
return None;
}
},
None => {},
if let Some(second_last) = second_iterator.next() {
if second_last.len() > 3 {
return None;
}
}
second.parse::<f64>().ok()?

View file

@ -74,17 +74,14 @@ impl<'a> ProcessDataURL for &'a HTMLObjectElement {
// Makes the local `data` member match the status of the `data` attribute and starts
/// prefetching the image. This method must be called after `data` is changed.
fn process_data_url(&self) {
let elem = self.upcast::<Element>();
let element = self.upcast::<Element>();
// TODO: support other values
match (
elem.get_attribute(&ns!(), &local_name!("type")),
elem.get_attribute(&ns!(), &local_name!("data")),
if let (None, Some(_uri)) = (
element.get_attribute(&ns!(), &local_name!("type")),
element.get_attribute(&ns!(), &local_name!("data")),
) {
(None, Some(_uri)) => {
// TODO(gw): Prefetch the image here.
},
_ => {},
// TODO(gw): Prefetch the image here.
}
}
}

View file

@ -2981,33 +2981,30 @@ impl NodeMethods for Node {
// same owner element.
if let Some(node2) = node2 {
if Some(node2) == node1 {
match (attr1, attr2) {
(Some(a1), Some(a2)) => {
let attrs = node2.downcast::<Element>().unwrap().attrs();
// go through the attrs in order to see if self
// or other is first; spec is clear that we
// want value-equality, not reference-equality
for attr in attrs.iter() {
if (*attr.namespace() == *a1.namespace()) &&
(attr.local_name() == a1.local_name()) &&
(**attr.value() == **a1.value())
{
return NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC +
NodeConstants::DOCUMENT_POSITION_PRECEDING;
}
if (*attr.namespace() == *a2.namespace()) &&
(attr.local_name() == a2.local_name()) &&
(**attr.value() == **a2.value())
{
return NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC +
NodeConstants::DOCUMENT_POSITION_FOLLOWING;
}
if let (Some(a1), Some(a2)) = (attr1, attr2) {
let attrs = node2.downcast::<Element>().unwrap().attrs();
// go through the attrs in order to see if self
// or other is first; spec is clear that we
// want value-equality, not reference-equality
for attr in attrs.iter() {
if (*attr.namespace() == *a1.namespace()) &&
(attr.local_name() == a1.local_name()) &&
(**attr.value() == **a1.value())
{
return NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC +
NodeConstants::DOCUMENT_POSITION_PRECEDING;
}
// both attrs have node2 as their owner element, so
// we can't have left the loop without seeing them
unreachable!();
},
(_, _) => {},
if (*attr.namespace() == *a2.namespace()) &&
(attr.local_name() == a2.local_name()) &&
(**attr.value() == **a2.value())
{
return NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC +
NodeConstants::DOCUMENT_POSITION_FOLLOWING;
}
}
// both attrs have node2 as their owner element, so
// we can't have left the loop without seeing them
unreachable!();
}
}
}

View file

@ -200,17 +200,14 @@ impl RTCDataChannel {
}
pub fn on_state_change(&self, state: DataChannelState) {
match state {
DataChannelState::Closing => {
let event = Event::new(
&self.global(),
atom!("closing"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
);
event.upcast::<Event>().fire(self.upcast());
},
_ => {},
if let DataChannelState::Closing = state {
let event = Event::new(
&self.global(),
atom!("closing"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
);
event.upcast::<Event>().fire(self.upcast());
};
self.ready_state.set(state.into());
}

View file

@ -724,65 +724,62 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
.pipeline_id(Some(self.global().pipeline_id()));
// step 4 (second half)
match content_type {
Some(content_type) => {
let encoding = match data {
Some(DocumentOrXMLHttpRequestBodyInit::String(_)) |
Some(DocumentOrXMLHttpRequestBodyInit::Document(_)) =>
// XHR spec differs from http, and says UTF-8 should be in capitals,
// instead of "utf-8", which is what Hyper defaults to. So not
// using content types provided by Hyper.
{
Some("UTF-8")
},
_ => None,
};
if let Some(content_type) = content_type {
let encoding = match data {
Some(DocumentOrXMLHttpRequestBodyInit::String(_)) |
Some(DocumentOrXMLHttpRequestBodyInit::Document(_)) =>
// XHR spec differs from http, and says UTF-8 should be in capitals,
// instead of "utf-8", which is what Hyper defaults to. So not
// using content types provided by Hyper.
{
Some("UTF-8")
},
_ => None,
};
let mut content_type_set = false;
if !request.headers.contains_key(header::CONTENT_TYPE) {
request.headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_str(&content_type).unwrap(),
);
content_type_set = true;
}
let mut content_type_set = false;
if !request.headers.contains_key(header::CONTENT_TYPE) {
request.headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_str(&content_type).unwrap(),
);
content_type_set = true;
}
if !content_type_set {
let ct = request.headers.typed_get::<ContentType>();
if let Some(ct) = ct {
if let Some(encoding) = encoding {
let mime: Mime = ct.into();
for param in mime.params() {
if param.0 == mime::CHARSET &&
!param.1.as_ref().eq_ignore_ascii_case(encoding)
{
let new_params: Vec<(Name, Name)> = mime
.params()
.filter(|p| p.0 != mime::CHARSET)
.map(|p| (p.0, p.1))
.collect();
if !content_type_set {
let ct = request.headers.typed_get::<ContentType>();
if let Some(ct) = ct {
if let Some(encoding) = encoding {
let mime: Mime = ct.into();
for param in mime.params() {
if param.0 == mime::CHARSET &&
!param.1.as_ref().eq_ignore_ascii_case(encoding)
{
let new_params: Vec<(Name, Name)> = mime
.params()
.filter(|p| p.0 != mime::CHARSET)
.map(|p| (p.0, p.1))
.collect();
let new_mime = format!(
"{}/{}; charset={}{}{}",
mime.type_().as_ref(),
mime.subtype().as_ref(),
encoding,
if new_params.is_empty() { "" } else { "; " },
new_params
.iter()
.map(|p| format!("{}={}", p.0, p.1))
.collect::<Vec<String>>()
.join("; ")
);
let new_mime: Mime = new_mime.parse().unwrap();
request.headers.typed_insert(ContentType::from(new_mime))
}
let new_mime = format!(
"{}/{}; charset={}{}{}",
mime.type_().as_ref(),
mime.subtype().as_ref(),
encoding,
if new_params.is_empty() { "" } else { "; " },
new_params
.iter()
.map(|p| format!("{}={}", p.0, p.1))
.collect::<Vec<String>>()
.join("; ")
);
let new_mime: Mime = new_mime.parse().unwrap();
request.headers.typed_insert(ContentType::from(new_mime))
}
}
}
}
},
_ => (),
}
}
self.fetch_time.set(time::now().to_timespec().sec);

View file

@ -2778,31 +2778,29 @@ impl ScriptThread {
Some(idx) => {
// https://html.spec.whatwg.org/multipage/#process-a-navigate-response
// 2. If response's status is 204 or 205, then abort these steps.
match metadata {
Some(Metadata {
status: Some((204..=205, _)),
..
}) => {
// If we have an existing window that is being navigated:
if let Some(window) = self.documents.borrow().find_window(*id) {
let window_proxy = window.window_proxy();
// https://html.spec.whatwg.org/multipage/
// #navigating-across-documents:delaying-load-events-mode-2
if window_proxy.parent().is_some() {
// The user agent must take this nested browsing context
// out of the delaying load events mode
// when this navigation algorithm later matures,
// or when it terminates (whether due to having run all the steps,
// or being canceled, or being aborted), whichever happens first.
window_proxy.stop_delaying_load_events_mode();
}
if let Some(Metadata {
status: Some((204..=205, _)),
..
}) = metadata
{
// If we have an existing window that is being navigated:
if let Some(window) = self.documents.borrow().find_window(*id) {
let window_proxy = window.window_proxy();
// https://html.spec.whatwg.org/multipage/
// #navigating-across-documents:delaying-load-events-mode-2
if window_proxy.parent().is_some() {
// The user agent must take this nested browsing context
// out of the delaying load events mode
// when this navigation algorithm later matures,
// or when it terminates (whether due to having run all the steps,
// or being canceled, or being aborted), whichever happens first.
window_proxy.stop_delaying_load_events_mode();
}
self.script_sender
.send((*id, ScriptMsg::AbortLoadUrl))
.unwrap();
return None;
},
_ => (),
}
self.script_sender
.send((*id, ScriptMsg::AbortLoadUrl))
.unwrap();
return None;
};
let load = self.incomplete_loads.borrow_mut().remove(idx);