Skip to content

Commit

Permalink
clippy: Fix option_map_unit_fn warnings (servo#31906)
Browse files Browse the repository at this point in the history
  • Loading branch information
oluwatobiss authored and ektuu committed Mar 28, 2024
1 parent 8d1d662 commit f3fd7ad
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 29 deletions.
4 changes: 2 additions & 2 deletions components/script/animations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ impl Animations {
pub(crate) fn cancel_animations_for_node(&self, node: &Node) {
let mut animations = self.sets.sets.write();
let mut cancel_animations_for = |key| {
animations.get_mut(&key).map(|set| {
if let Some(set) = animations.get_mut(&key) {
set.cancel_all_animations();
});
}
};

let opaque_node = node.to_opaque();
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/csskeyframesrule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ impl SpecificCSSRule for CSSKeyframesRule {
}

fn deparent_children(&self) {
self.rulelist.get().map(|list| list.deparent_all());
if let Some(list) = self.rulelist.get() {
list.deparent_all()
}
}
}
12 changes: 9 additions & 3 deletions components/script/dom/cssrulelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,18 @@ impl CSSRuleList {
RulesSource::Rules(ref css_rules) => {
css_rules.write_with(&mut guard).remove_rule(index)?;
let mut dom_rules = self.dom_rules.borrow_mut();
dom_rules[index].get().map(|r| r.detach());
if let Some(r) = dom_rules[index].get() {
r.detach()
}
dom_rules.remove(index);
Ok(())
},
RulesSource::Keyframes(ref kf) => {
// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-deleterule
let mut dom_rules = self.dom_rules.borrow_mut();
dom_rules[index].get().map(|r| r.detach());
if let Some(r) = dom_rules[index].get() {
r.detach()
}
dom_rules.remove(index);
kf.write_with(&mut guard).keyframes.remove(index);
Ok(())
Expand All @@ -162,7 +166,9 @@ impl CSSRuleList {
// Remove parent stylesheets from all children
pub fn deparent_all(&self) {
for rule in self.dom_rules.borrow().iter() {
rule.get().map(|r| DomRoot::upcast(r).deparent());
if let Some(r) = rule.get() {
DomRoot::upcast(r).deparent()
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions components/script/dom/htmlinputelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2832,18 +2832,20 @@ impl Activatable for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#submit-button-state-(type=submit):activation-behavior
// FIXME (Manishearth): support document owners (needs ability to get parent browsing context)
// Check if document owner is fully active
self.form_owner().map(|o| {
if let Some(o) = self.form_owner() {
o.submit(
SubmittedFrom::NotFromForm,
FormSubmitter::InputElement(self),
)
});
}
},
InputType::Reset => {
// https://html.spec.whatwg.org/multipage/#reset-button-state-(type=reset):activation-behavior
// FIXME (Manishearth): support document owners (needs ability to get parent browsing context)
// Check if document owner is fully active
self.form_owner().map(|o| o.reset(ResetFrom::NotFromForm));
if let Some(o) = self.form_owner() {
o.reset(ResetFrom::NotFromForm)
}
},
InputType::Checkbox | InputType::Radio => {
// https://html.spec.whatwg.org/multipage/#checkbox-state-(type=checkbox):activation-behavior
Expand Down
12 changes: 5 additions & 7 deletions components/script/dom/htmlmediaelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,23 +1432,21 @@ impl HTMLMediaElement {

match msg {
GLPlayerMsgForward::Lock(sender) => {
video_renderer
if let Some(holder) = video_renderer
.lock()
.unwrap()
.current_frame_holder
.as_mut()
.map(|holder| {
.as_mut() {
holder.lock();
sender.send(holder.get()).unwrap();
});
};
},
GLPlayerMsgForward::Unlock() => {
video_renderer
if let Some(holder) = video_renderer
.lock()
.unwrap()
.current_frame_holder
.as_mut()
.map(|holder| holder.unlock());
.as_mut() { holder.unlock() }
},
_ => (),
}
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/servoparser/async_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ impl Tokenizer {
},
ParseOperation::MarkScriptAlreadyStarted { node } => {
let script = self.get_node(&node).downcast::<HTMLScriptElement>();
script.map(|script| script.set_already_started(true));
if let Some(script) = script {
script.set_already_started(true)
}
},
ParseOperation::ReparentChildren { parent, new_parent } => {
let parent = self.get_node(&parent);
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/servoparser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,9 @@ impl TreeSink for Sink {

fn mark_script_already_started(&mut self, node: &Dom<Node>) {
let script = node.downcast::<HTMLScriptElement>();
script.map(|script| script.set_already_started(true));
if let Some(script) = script {
script.set_already_started(true)
}
}

fn complete_script(&mut self, node: &Dom<Node>) -> NextParserState {
Expand Down
7 changes: 3 additions & 4 deletions components/script/dom/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,9 @@ impl WorkerMethods for Worker {
self.terminated.set(true);

// Step 3
self.context_for_interrupt
.borrow()
.as_ref()
.map(|cx| cx.request_interrupt());
if let Some(cx) = self.context_for_interrupt.borrow().as_ref() {
cx.request_interrupt()
}
}

// https://html.spec.whatwg.org/multipage/#handler-worker-onmessage
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/worklet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ struct DroppableField {
impl Drop for DroppableField {
fn drop(&mut self) {
let worklet_id = self.worklet_id;
self.thread_pool.get_mut().map(|thread_pool| {
if let Some(thread_pool) = self.thread_pool.get_mut() {
thread_pool.exit_worklet(worklet_id);
});
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions components/script/dom/xmlhttprequest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,13 +1127,13 @@ impl XMLHttpRequest {
// Part of step 13, send() (processing response)
// XXXManishearth handle errors, if any (substep 1)
// Substep 2
status.map(|(code, reason)| {
if let Some((code, reason)) = status {
self.status.set(code);
*self.status_text.borrow_mut() = ByteString::new(reason);
});
headers
.as_ref()
.map(|h| *self.response_headers.borrow_mut() = h.clone());
}
if let Some(h) = headers.as_ref() {
*self.response_headers.borrow_mut() = h.clone();
}
{
let len = headers.and_then(|h| h.typed_get::<ContentLength>());
let mut response = self.response.borrow_mut();
Expand Down

0 comments on commit f3fd7ad

Please sign in to comment.