From 21ea6d21f0f3bcb2e736082e397ef99cf9ecd051 Mon Sep 17 00:00:00 2001 From: Oluwatobi Sofela <60105594+oluwatobiss@users.noreply.github.com> Date: Fri, 19 Apr 2024 03:47:40 +0100 Subject: [PATCH] clippy: Fix `explicit_auto_deref` warnings in `components/script` (#32113) * clippy: Fix explicit_auto_deref warnings * refactor: Change basic comments to rustdoc comments --- components/script/dom/elementinternals.rs | 2 +- components/script/dom/globalscope.rs | 4 +- components/script/dom/node.rs | 118 +++++++++++----------- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/components/script/dom/elementinternals.rs b/components/script/dom/elementinternals.rs index 945d4f6b265..ed1f4cdd681 100644 --- a/components/script/dom/elementinternals.rs +++ b/components/script/dom/elementinternals.rs @@ -294,7 +294,7 @@ impl ElementInternalsMethods for ElementInternals { Ok(self.labels_node_list.or_init(|| { NodeList::new_labels_list( self.target_element.upcast::().owner_doc().window(), - &*self.target_element, + &self.target_element, ) })) } diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index f8904955fc3..bb9c6ca6f72 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -3023,7 +3023,7 @@ impl GlobalScope { unreachable!(); } - // https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute + /// pub fn supported_performance_entry_types(&self, cx: SafeJSContext) -> JSVal { if let Some(types) = &*self.frozen_supported_performance_entry_types.borrow() { return types.get(); @@ -3152,7 +3152,7 @@ impl GlobalScope { let navigator = window.Navigator(); let selected_index = navigator.select_gamepad_index(); let gamepad = Gamepad::new(&global, selected_index, name, axis_bounds, button_bounds); - navigator.set_gamepad(selected_index as usize, &*gamepad); + navigator.set_gamepad(selected_index as usize, &gamepad); } }), &self.task_canceller(TaskSourceName::Gamepad) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 9e6a98a63dc..3bf396609ca 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -389,7 +389,7 @@ impl Node { }) } - // https://html.spec.whatg.org/#fire_a_synthetic_mouse_event + /// pub fn fire_synthetic_mouse_event_not_trusted(&self, name: DOMString) { // Spec says the choice of which global to create // the mouse event on is not well-defined, @@ -596,7 +596,7 @@ impl Node { } } - // https://dom.spec.whatwg.org/#concept-node-length + /// pub fn len(&self) -> u32 { match self.type_id() { NodeTypeId::DocumentType => 0, @@ -605,7 +605,7 @@ impl Node { } } - // https://dom.spec.whatwg.org/#concept-tree-index + /// pub fn index(&self) -> u32 { self.preceding_siblings().count() as u32 } @@ -807,8 +807,8 @@ impl Node { window_from_node(self).client_rect_query(self) } - // https://drafts.csswg.org/cssom-view/#dom-element-scrollwidth - // https://drafts.csswg.org/cssom-view/#dom-element-scrollheight + /// + /// pub fn scroll_area(&self) -> Rect { // "1. Let document be the element’s node document."" let document = self.owner_doc(); @@ -854,7 +854,7 @@ impl Node { window.scroll_offset_query(self).to_untyped() } - // https://dom.spec.whatwg.org/#dom-childnode-before + /// pub fn before(&self, nodes: Vec) -> ErrorResult { // Step 1. let parent = &self.parent_node; @@ -883,7 +883,7 @@ impl Node { Ok(()) } - // https://dom.spec.whatwg.org/#dom-childnode-after + /// pub fn after(&self, nodes: Vec) -> ErrorResult { // Step 1. let parent = &self.parent_node; @@ -906,7 +906,7 @@ impl Node { Ok(()) } - // https://dom.spec.whatwg.org/#dom-childnode-replacewith + /// pub fn replace_with(&self, nodes: Vec) -> ErrorResult { // Step 1. let parent = if let Some(parent) = self.GetParentNode() { @@ -929,7 +929,7 @@ impl Node { Ok(()) } - // https://dom.spec.whatwg.org/#dom-parentnode-prepend + /// pub fn prepend(&self, nodes: Vec) -> ErrorResult { // Step 1. let doc = self.owner_doc(); @@ -939,7 +939,7 @@ impl Node { Node::pre_insert(&node, self, first_child.as_deref()).map(|_| ()) } - // https://dom.spec.whatwg.org/#dom-parentnode-append + /// pub fn append(&self, nodes: Vec) -> ErrorResult { // Step 1. let doc = self.owner_doc(); @@ -948,7 +948,7 @@ impl Node { self.AppendChild(&node).map(|_| ()) } - // https://dom.spec.whatwg.org/#dom-parentnode-replacechildren + /// pub fn replace_children(&self, nodes: Vec) -> ErrorResult { // Step 1. let doc = self.owner_doc(); @@ -960,7 +960,7 @@ impl Node { Ok(()) } - // https://dom.spec.whatwg.org/#dom-parentnode-queryselector + /// pub fn query_selector(&self, selectors: DOMString) -> Fallible>> { // Step 1. let doc = self.owner_doc(); @@ -1012,7 +1012,7 @@ impl Node { } } - // https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall + /// #[allow(unsafe_code)] pub fn query_selector_all(&self, selectors: DOMString) -> Fallible> { let window = window_from_node(self); @@ -1638,7 +1638,7 @@ impl FollowingNodeIterator { impl Iterator for FollowingNodeIterator { type Item = DomRoot; - // https://dom.spec.whatwg.org/#concept-tree-following + /// fn next(&mut self) -> Option> { let current = self.current.take()?; @@ -1659,7 +1659,7 @@ pub struct PrecedingNodeIterator { impl Iterator for PrecedingNodeIterator { type Item = DomRoot; - // https://dom.spec.whatwg.org/#concept-tree-preceding + /// fn next(&mut self) -> Option> { let current = self.current.take()?; @@ -1755,8 +1755,8 @@ impl TreeIterator { impl Iterator for TreeIterator { type Item = DomRoot; - // https://dom.spec.whatwg.org/#concept-tree-order - // https://dom.spec.whatwg.org/#concept-shadow-including-tree-order + /// + /// fn next(&mut self) -> Option> { let current = self.current.take()?; @@ -1840,7 +1840,7 @@ impl Node { } } - // https://dom.spec.whatwg.org/#concept-node-adopt + /// pub fn adopt(node: &Node, document: &Document) { document.add_script_and_layout_blocker(); @@ -1876,7 +1876,7 @@ impl Node { document.remove_script_and_layout_blocker(); } - // https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity + /// pub fn ensure_pre_insertion_validity( node: &Node, parent: &Node, @@ -1994,7 +1994,7 @@ impl Node { Ok(()) } - // https://dom.spec.whatwg.org/#concept-node-pre-insert + /// pub fn pre_insert(node: &Node, parent: &Node, child: Option<&Node>) -> Fallible> { // Step 1. Node::ensure_pre_insertion_validity(node, parent, child)?; @@ -2025,7 +2025,7 @@ impl Node { Ok(DomRoot::from_ref(node)) } - // https://dom.spec.whatwg.org/#concept-node-insert + /// fn insert( node: &Node, parent: &Node, @@ -2102,7 +2102,7 @@ impl Node { ); } } else { - try_upgrade_element(&*descendant); + try_upgrade_element(&descendant); } } } @@ -2124,7 +2124,7 @@ impl Node { node.owner_doc().remove_script_and_layout_blocker(); } - // https://dom.spec.whatwg.org/#concept-node-replace-all + /// pub fn replace_all(node: Option<&Node>, parent: &Node) { parent.owner_doc().add_script_and_layout_blocker(); // Step 1. @@ -2171,7 +2171,7 @@ impl Node { parent.owner_doc().remove_script_and_layout_blocker(); } - // https://dom.spec.whatwg.org/multipage/#string-replace-all + /// pub fn string_replace_all(string: DOMString, parent: &Node) { if string.len() == 0 { Node::replace_all(None, parent); @@ -2181,7 +2181,7 @@ impl Node { }; } - // https://dom.spec.whatwg.org/#concept-node-pre-remove + /// fn pre_remove(child: &Node, parent: &Node) -> Fallible> { // Step 1. match child.GetParentNode() { @@ -2197,7 +2197,7 @@ impl Node { Ok(DomRoot::from_ref(child)) } - // https://dom.spec.whatwg.org/#concept-node-remove + /// fn remove(node: &Node, parent: &Node, suppress_observers: SuppressObserver) { parent.owner_doc().add_script_and_layout_blocker(); assert!(node @@ -2247,7 +2247,7 @@ impl Node { parent.owner_doc().remove_script_and_layout_blocker(); } - // https://dom.spec.whatwg.org/#concept-node-clone + /// pub fn clone( node: &Node, maybe_doc: Option<&Document>, @@ -2440,7 +2440,7 @@ impl Node { } impl NodeMethods for Node { - // https://dom.spec.whatwg.org/#dom-node-nodetype + /// fn NodeType(&self) -> u16 { match self.type_id() { NodeTypeId::Attr => NodeConstants::ATTRIBUTE_NODE, @@ -2461,7 +2461,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-nodename + /// fn NodeName(&self) -> DOMString { match self.type_id() { NodeTypeId::Attr => self.downcast::().unwrap().qualified_name(), @@ -2482,17 +2482,17 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-baseuri + /// fn BaseURI(&self) -> USVString { USVString(String::from(self.owner_doc().base_url().as_str())) } - // https://dom.spec.whatwg.org/#dom-node-isconnected + /// fn IsConnected(&self) -> bool { self.is_connected() } - // https://dom.spec.whatwg.org/#dom-node-ownerdocument + /// fn GetOwnerDocument(&self) -> Option> { match self.type_id() { NodeTypeId::Document(_) => None, @@ -2500,7 +2500,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-getrootnode + /// fn GetRootNode(&self, options: &GetRootNodeOptions) -> DomRoot { if let Some(shadow_root) = self.containing_shadow_root() { return if options.composed { @@ -2520,22 +2520,22 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-parentnode + /// fn GetParentNode(&self) -> Option> { self.parent_node.get() } - // https://dom.spec.whatwg.org/#dom-node-parentelement + /// fn GetParentElement(&self) -> Option> { self.GetParentNode().and_then(DomRoot::downcast) } - // https://dom.spec.whatwg.org/#dom-node-haschildnodes + /// fn HasChildNodes(&self) -> bool { self.first_child.get().is_some() } - // https://dom.spec.whatwg.org/#dom-node-childnodes + /// fn ChildNodes(&self) -> DomRoot { self.child_list.or_init(|| { let doc = self.owner_doc(); @@ -2544,27 +2544,27 @@ impl NodeMethods for Node { }) } - // https://dom.spec.whatwg.org/#dom-node-firstchild + /// fn GetFirstChild(&self) -> Option> { self.first_child.get() } - // https://dom.spec.whatwg.org/#dom-node-lastchild + /// fn GetLastChild(&self) -> Option> { self.last_child.get() } - // https://dom.spec.whatwg.org/#dom-node-previoussibling + /// fn GetPreviousSibling(&self) -> Option> { self.prev_sibling.get() } - // https://dom.spec.whatwg.org/#dom-node-nextsibling + /// fn GetNextSibling(&self) -> Option> { self.next_sibling.get() } - // https://dom.spec.whatwg.org/#dom-node-nodevalue + /// fn GetNodeValue(&self) -> Option { match self.type_id() { NodeTypeId::Attr => Some(self.downcast::().unwrap().Value()), @@ -2575,7 +2575,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-nodevalue + /// fn SetNodeValue(&self, val: Option) { match self.type_id() { NodeTypeId::Attr => { @@ -2590,7 +2590,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-textcontent + /// fn GetTextContent(&self) -> Option { match self.type_id() { NodeTypeId::DocumentFragment(_) | NodeTypeId::Element(..) => { @@ -2607,7 +2607,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-textcontent + /// fn SetTextContent(&self, value: Option) { let value = value.unwrap_or_default(); match self.type_id() { @@ -2634,17 +2634,17 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-insertbefore + /// fn InsertBefore(&self, node: &Node, child: Option<&Node>) -> Fallible> { Node::pre_insert(node, self, child) } - // https://dom.spec.whatwg.org/#dom-node-appendchild + /// fn AppendChild(&self, node: &Node) -> Fallible> { Node::pre_insert(node, self, None) } - // https://dom.spec.whatwg.org/#concept-node-replace + /// fn ReplaceChild(&self, node: &Node, child: &Node) -> Fallible> { // Step 1. match self.type_id() { @@ -2789,12 +2789,12 @@ impl NodeMethods for Node { Ok(DomRoot::from_ref(child)) } - // https://dom.spec.whatwg.org/#dom-node-removechild + /// fn RemoveChild(&self, node: &Node) -> Fallible> { Node::pre_remove(node, self) } - // https://dom.spec.whatwg.org/#dom-node-normalize + /// fn Normalize(&self) { let mut children = self.children().enumerate().peekable(); while let Some((_, node)) = children.next() { @@ -2826,7 +2826,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-clonenode + /// fn CloneNode(&self, deep: bool) -> Fallible> { if deep && self.is::() { return Err(Error::NotSupported); @@ -2842,7 +2842,7 @@ impl NodeMethods for Node { )) } - // https://dom.spec.whatwg.org/#dom-node-isequalnode + /// fn IsEqualNode(&self, maybe_node: Option<&Node>) -> bool { fn is_equal_doctype(node: &Node, other: &Node) -> bool { let doctype = node.downcast::().unwrap(); @@ -2937,7 +2937,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-issamenode + /// fn IsSameNode(&self, other_node: Option<&Node>) -> bool { match other_node { Some(node) => self == node, @@ -2945,7 +2945,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-comparedocumentposition + /// fn CompareDocumentPosition(&self, other: &Node) -> u16 { // step 1. if self == other { @@ -3099,7 +3099,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-contains + /// fn Contains(&self, maybe_other: Option<&Node>) -> bool { match maybe_other { None => false, @@ -3107,7 +3107,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-lookupprefix + /// fn LookupPrefix(&self, namespace: Option) -> Option { let namespace = namespace_from_domstring(namespace); @@ -3136,7 +3136,7 @@ impl NodeMethods for Node { } } - // https://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri + /// fn LookupNamespaceURI(&self, prefix: Option) -> Option { // Step 1. let prefix = match prefix { @@ -3148,7 +3148,7 @@ impl NodeMethods for Node { Node::namespace_to_string(Node::locate_namespace(self, prefix)) } - // https://dom.spec.whatwg.org/#dom-node-isdefaultnamespace + /// fn IsDefaultNamespace(&self, namespace: Option) -> bool { // Step 1. let namespace = namespace_from_domstring(namespace); @@ -3199,7 +3199,7 @@ impl VirtualMethods for Node { } // This handles the ranges mentioned in steps 2-3 when removing a node. - // https://dom.spec.whatwg.org/#concept-node-remove + /// fn unbind_from_tree(&self, context: &UnbindContext) { self.super_type().unwrap().unbind_from_tree(context); self.ranges.drain_to_parent(context, self);