mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
clippy: Fix another set of clippy problems in components/script/dom
(#31909)
* a reference to a reference * length comparison to zero * length comparison to zero * length comparison to zero
This commit is contained in:
parent
af358f51db
commit
18054d0737
5 changed files with 19 additions and 19 deletions
|
@ -933,7 +933,7 @@ impl Document {
|
|||
pub fn register_form_id_listener<T: ?Sized + FormControl>(&self, id: DOMString, listener: &T) {
|
||||
let mut map = self.form_id_listener_map.borrow_mut();
|
||||
let listener = listener.to_element();
|
||||
let set = map.entry(Atom::from(id)).or_insert(HashSet::new());
|
||||
let set = map.entry(Atom::from(id)).or_default();
|
||||
set.insert(Dom::from_ref(listener));
|
||||
}
|
||||
|
||||
|
@ -1075,7 +1075,7 @@ impl Document {
|
|||
|
||||
/// <https://html.spec.whatwg.org/multipage/#focus-fixup-rule>
|
||||
pub(crate) fn perform_focus_fixup_rule(&self, not_focusable: &Element) {
|
||||
if Some(not_focusable) != self.focused.get().as_ref().map(|e| &**e) {
|
||||
if Some(not_focusable) != self.focused.get().as_deref() {
|
||||
return;
|
||||
}
|
||||
self.request_focus(
|
||||
|
@ -1114,7 +1114,7 @@ impl Document {
|
|||
},
|
||||
};
|
||||
*self.focus_transaction.borrow_mut() = FocusTransaction::NotInTransaction;
|
||||
if self.focused == possibly_focused.as_ref().map(|e| &**e) {
|
||||
if self.focused == possibly_focused.as_deref() {
|
||||
return;
|
||||
}
|
||||
if let Some(ref elem) = self.focused.get() {
|
||||
|
@ -1129,7 +1129,7 @@ impl Document {
|
|||
}
|
||||
}
|
||||
|
||||
self.focused.set(possibly_focused.as_ref().map(|e| &**e));
|
||||
self.focused.set(possibly_focused.as_deref());
|
||||
|
||||
if let Some(ref elem) = self.focused.get() {
|
||||
elem.set_focus_state(true);
|
||||
|
@ -1152,7 +1152,7 @@ impl Document {
|
|||
let (text, multiline) = if let Some(input) = elem.downcast::<HTMLInputElement>() {
|
||||
(
|
||||
Some((
|
||||
(&input.Value()).to_string(),
|
||||
input.Value().to_string(),
|
||||
input.GetSelectionEnd().unwrap_or(0) as i32,
|
||||
)),
|
||||
false,
|
||||
|
@ -1160,7 +1160,7 @@ impl Document {
|
|||
} else if let Some(textarea) = elem.downcast::<HTMLTextAreaElement>() {
|
||||
(
|
||||
Some((
|
||||
(&textarea.Value()).to_string(),
|
||||
textarea.Value().to_string(),
|
||||
textarea.GetSelectionEnd().unwrap_or(0) as i32,
|
||||
)),
|
||||
true,
|
||||
|
@ -1188,7 +1188,7 @@ impl Document {
|
|||
title.clone(),
|
||||
));
|
||||
let global = self.window.upcast::<GlobalScope>();
|
||||
if let Some(ref chan) = global.devtools_chan() {
|
||||
if let Some(chan) = global.devtools_chan() {
|
||||
let _ = chan.send(ScriptToDevtoolsControlMsg::TitleChanged(
|
||||
global.pipeline_id(),
|
||||
title,
|
||||
|
@ -3031,7 +3031,7 @@ fn get_registrable_domain_suffix_of_or_is_equal_to(
|
|||
let index = original_host.len().checked_sub(host.len())?;
|
||||
let (prefix, suffix) = original_host.split_at(index);
|
||||
|
||||
if !prefix.ends_with(".") {
|
||||
if !prefix.ends_with('.') {
|
||||
return None;
|
||||
}
|
||||
if suffix != host {
|
||||
|
|
|
@ -287,7 +287,7 @@ impl DocumentOrShadowRoot {
|
|||
assert!(element.upcast::<Node>().is_connected());
|
||||
assert!(!id.is_empty());
|
||||
let mut id_map = id_map.borrow_mut();
|
||||
let elements = id_map.entry(id.clone()).or_insert(Vec::new());
|
||||
let elements = id_map.entry(id.clone()).or_default();
|
||||
elements.insert_pre_order(element, &root);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ impl DOMTokenList {
|
|||
// https://dom.spec.whatwg.org/#concept-dtl-update
|
||||
fn perform_update_steps(&self, atoms: Vec<Atom>) {
|
||||
// Step 1
|
||||
if !self.element.has_attribute(&self.local_name) && atoms.len() == 0 {
|
||||
if !self.element.has_attribute(&self.local_name) && atoms.is_empty() {
|
||||
return;
|
||||
}
|
||||
// step 2
|
||||
|
|
|
@ -1217,7 +1217,7 @@ impl Element {
|
|||
// "3. If its namespace is non-null and its namespace prefix is prefix, then return
|
||||
// namespace."
|
||||
if element.namespace() != &ns!() &&
|
||||
element.prefix().as_ref().map(|p| &**p) == prefix.as_ref().map(|p| &**p)
|
||||
element.prefix().as_ref().map(|p| &**p) == prefix.as_deref()
|
||||
{
|
||||
return element.namespace().clone();
|
||||
}
|
||||
|
@ -1548,7 +1548,7 @@ impl Element {
|
|||
|
||||
pub fn set_attribute(&self, name: &LocalName, value: AttrValue) {
|
||||
assert!(name == &name.to_ascii_lowercase());
|
||||
assert!(!name.contains(":"));
|
||||
assert!(!name.contains(':'));
|
||||
|
||||
self.set_first_matching_attribute(name.clone(), value, name.clone(), ns!(), None, |attr| {
|
||||
attr.local_name() == name
|
||||
|
@ -1725,7 +1725,7 @@ impl Element {
|
|||
pub fn get_tokenlist_attribute(&self, local_name: &LocalName) -> Vec<Atom> {
|
||||
self.get_attribute(&ns!(), local_name)
|
||||
.map(|attr| attr.value().as_tokens().to_vec())
|
||||
.unwrap_or(vec![])
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn set_tokenlist_attribute(&self, local_name: &LocalName, value: DOMString) {
|
||||
|
@ -3066,7 +3066,7 @@ impl VirtualMethods for Element {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -3149,7 +3149,7 @@ impl VirtualMethods for Element {
|
|||
}
|
||||
|
||||
fn children_changed(&self, mutation: &ChildrenMutation) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
if let Some(s) = self.super_type() {
|
||||
s.children_changed(mutation);
|
||||
}
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ impl CompiledEventListener {
|
|||
if let Ok(return_value) = return_value {
|
||||
rooted!(in(*cx) let return_value = return_value);
|
||||
if return_value.handle().is_boolean() &&
|
||||
return_value.handle().to_boolean() == true
|
||||
return_value.handle().to_boolean()
|
||||
{
|
||||
event.upcast::<Event>().PreventDefault();
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ impl CompiledEventListener {
|
|||
let value = value.handle();
|
||||
|
||||
//Step 5
|
||||
let should_cancel = value.is_boolean() && value.to_boolean() == false;
|
||||
let should_cancel = value.is_boolean() && !value.to_boolean();
|
||||
|
||||
if should_cancel {
|
||||
// FIXME: spec says to set the cancelled flag directly
|
||||
|
@ -342,7 +342,7 @@ impl EventListeners {
|
|||
fn has_listeners(&self) -> bool {
|
||||
// TODO: add, and take into account, a 'removed' field?
|
||||
// https://dom.spec.whatwg.org/#event-listener-removed
|
||||
self.0.len() > 0
|
||||
!self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,7 +417,7 @@ impl EventTarget {
|
|||
|
||||
let idx = entries
|
||||
.iter()
|
||||
.position(|ref entry| matches!(entry.listener, EventListenerType::Inline(_)));
|
||||
.position(|entry| matches!(entry.listener, EventListenerType::Inline(_)));
|
||||
|
||||
match idx {
|
||||
Some(idx) => match listener {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue