From b55d0a20532b915dee395f8c448ac832ed36b7d4 Mon Sep 17 00:00:00 2001 From: Oluwatobi Sofela <60105594+oluwatobiss@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:55:20 +0100 Subject: [PATCH] clippy: Fix clone-on-copy warnings (#31877) --- components/script/animations.rs | 4 +- components/script/body.rs | 10 ++--- components/script/dom/bindings/root.rs | 4 +- .../script/dom/bindings/structuredclone.rs | 2 +- components/script/dom/blob.rs | 13 +++--- .../script/dom/bluetoothadvertisingevent.rs | 6 +-- components/script/dom/cssstyledeclaration.rs | 2 +- components/script/dom/dommatrix.rs | 2 +- components/script/dom/globalscope.rs | 45 +++++++++---------- 9 files changed, 41 insertions(+), 47 deletions(-) diff --git a/components/script/animations.rs b/components/script/animations.rs index 128df043cf3..df8378a37b9 100644 --- a/components/script/animations.rs +++ b/components/script/animations.rs @@ -397,7 +397,7 @@ impl Animations { pipeline_id, event_type, node: key.node, - pseudo_element: key.pseudo_element.clone(), + pseudo_element: key.pseudo_element, property_or_animation_name: transition .property_animation .property_id() @@ -450,7 +450,7 @@ impl Animations { pipeline_id, event_type, node: key.node, - pseudo_element: key.pseudo_element.clone(), + pseudo_element: key.pseudo_element, property_or_animation_name: animation.name.to_string(), elapsed_time, }); diff --git a/components/script/body.rs b/components/script/body.rs index bad9c86d446..c1cd40940e5 100644 --- a/components/script/body.rs +++ b/components/script/body.rs @@ -287,7 +287,7 @@ struct TransmitBodyPromiseHandler { impl Callback for TransmitBodyPromiseHandler { /// Step 5 of fn callback(&self, cx: JSContext, v: HandleValue, _realm: InRealm) { - let is_done = match get_read_promise_done(cx.clone(), &v) { + let is_done = match get_read_promise_done(cx, &v) { Ok(is_done) => is_done, Err(_) => { // Step 5.5, the "otherwise" steps. @@ -304,7 +304,7 @@ impl Callback for TransmitBodyPromiseHandler { return self.stream.stop_reading(); } - let chunk = match get_read_promise_bytes(cx.clone(), &v) { + let chunk = match get_read_promise_bytes(cx, &v) { Ok(chunk) => chunk, Err(_) => { // Step 5.5, the "otherwise" steps. @@ -656,7 +656,7 @@ impl Callback for ConsumeBodyPromiseHandler { .as_ref() .expect("ConsumeBodyPromiseHandler has no stream in callback."); - let is_done = match get_read_promise_done(cx.clone(), &v) { + let is_done = match get_read_promise_done(cx, &v) { Ok(is_done) => is_done, Err(err) => { stream.stop_reading(); @@ -667,9 +667,9 @@ impl Callback for ConsumeBodyPromiseHandler { if is_done { // When read is fulfilled with an object whose done property is true. - self.resolve_result_promise(cx.clone()); + self.resolve_result_promise(cx); } else { - let chunk = match get_read_promise_bytes(cx.clone(), &v) { + let chunk = match get_read_promise_bytes(cx, &v) { Ok(chunk) => chunk, Err(err) => { stream.stop_reading(); diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index c6057b9c943..088f93d12e0 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -509,9 +509,7 @@ impl Clone for Dom { #[allow(crown::unrooted_must_root)] fn clone(&self) -> Self { assert_in_script(); - Dom { - ptr: self.ptr.clone(), - } + Dom { ptr: self.ptr } } } diff --git a/components/script/dom/bindings/structuredclone.rs b/components/script/dom/bindings/structuredclone.rs index e122a1336b3..d9c17d129ea 100644 --- a/components/script/dom/bindings/structuredclone.rs +++ b/components/script/dom/bindings/structuredclone.rs @@ -65,7 +65,7 @@ unsafe fn read_blob( &mut index as *mut u32 )); let storage_key = StorageKey { index, name_space }; - if ::deserialize(owner, sc_holder, storage_key.clone()).is_ok() { + if ::deserialize(owner, sc_holder, storage_key).is_ok() { let blobs = match sc_holder { StructuredDataHolder::Read { blobs, .. } => blobs, _ => panic!("Unexpected variant of StructuredDataHolder"), diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index 38d6e0c4012..6f63abf85e4 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -116,7 +116,7 @@ impl Serializable for Blob { _ => panic!("Unexpected variant of StructuredDataHolder"), }; - let blob_id = self.blob_id.clone(); + let blob_id = self.blob_id; // 1. Get a clone of the blob impl. let blob_impl = self.global().serialize_blob(&blob_id); @@ -126,7 +126,7 @@ impl Serializable for Blob { // 2. Store the object at a given key. let blobs = blob_impls.get_or_insert_with(|| HashMap::new()); - blobs.insert(new_blob_id.clone(), blob_impl); + blobs.insert(new_blob_id, blob_impl); let PipelineNamespaceId(name_space) = new_blob_id.namespace_id; let BlobIndex(index) = new_blob_id.index; @@ -152,10 +152,9 @@ impl Serializable for Blob { ) -> Result<(), ()> { // 1. Re-build the key for the storage location // of the serialized object. - let namespace_id = PipelineNamespaceId(storage_key.name_space.clone()); - let index = BlobIndex( - NonZeroU32::new(storage_key.index.clone()).expect("Deserialized blob index is zero"), - ); + let namespace_id = PipelineNamespaceId(storage_key.name_space); + let index = + BlobIndex(NonZeroU32::new(storage_key.index).expect("Deserialized blob index is zero")); let id = BlobId { namespace_id, @@ -245,7 +244,7 @@ impl BlobMethods for Blob { let type_string = normalize_type_string(&content_type.unwrap_or(DOMString::from("")).to_string()); let rel_pos = RelativePos::from_opts(start, end); - let blob_impl = BlobImpl::new_sliced(rel_pos, self.blob_id.clone(), type_string); + let blob_impl = BlobImpl::new_sliced(rel_pos, self.blob_id, type_string); Blob::new(&self.global(), blob_impl) } diff --git a/components/script/dom/bluetoothadvertisingevent.rs b/components/script/dom/bluetoothadvertisingevent.rs index a8697bbde41..d24ad715036 100644 --- a/components/script/dom/bluetoothadvertisingevent.rs +++ b/components/script/dom/bluetoothadvertisingevent.rs @@ -85,9 +85,9 @@ impl BluetoothAdvertisingEvent { ) -> Fallible> { let global = window.upcast::(); let name = init.name.clone(); - let appearance = init.appearance.clone(); - let txPower = init.txPower.clone(); - let rssi = init.rssi.clone(); + let appearance = init.appearance; + let txPower = init.txPower; + let rssi = init.rssi; let bubbles = EventBubbles::from(init.parent.bubbles); let cancelable = EventCancelable::from(init.parent.cancelable); Ok(BluetoothAdvertisingEvent::new( diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index fcfb94f1ec5..36eda0aed87 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -257,7 +257,7 @@ impl CSSStyleDeclaration { return DOMString::new(); } let addr = node.to_trusted_node_address(); - window_from_node(node).resolved_style_query(addr, self.pseudo.clone(), property) + window_from_node(node).resolved_style_query(addr, self.pseudo, property) }, } } diff --git a/components/script/dom/dommatrix.rs b/components/script/dom/dommatrix.rs index c4430f5001b..cda2b4a9c18 100644 --- a/components/script/dom/dommatrix.rs +++ b/components/script/dom/dommatrix.rs @@ -89,7 +89,7 @@ impl DOMMatrix { } pub fn from_readonly(global: &GlobalScope, ro: &DOMMatrixReadOnly) -> DomRoot { - Self::new(global, ro.is2D(), ro.matrix().clone()) + Self::new(global, ro.is2D(), *ro.matrix()) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-fromfloat32array diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 1389b586292..2b02a1eae82 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -556,7 +556,7 @@ impl MessageListener { for (id, buffer) in ports.into_iter() { if global.is_managing_port(&id) { - succeeded.push(id.clone()); + succeeded.push(id); global.complete_port_transfer(id, buffer); } else { failed.insert(id, buffer); @@ -804,7 +804,7 @@ impl GlobalScope { /// The message-port router Id of the global, if any fn port_router_id(&self) -> Option { if let MessagePortState::Managed(id, _message_ports) = &*self.message_port_state.borrow() { - Some(id.clone()) + Some(*id) } else { None } @@ -869,8 +869,7 @@ impl GlobalScope { } // Step 2.1 -> 2.5 - let new_registration = - ServiceWorkerRegistration::new(self, scope.clone(), registration_id.clone()); + let new_registration = ServiceWorkerRegistration::new(self, scope.clone(), registration_id); // Step 2.6 if let Some(worker_id) = installing_worker { @@ -905,8 +904,7 @@ impl GlobalScope { } else { // Step 2.1 // TODO: step 2.2, worker state. - let new_worker = - ServiceWorker::new(self, script_url.clone(), scope.clone(), worker_id.clone()); + let new_worker = ServiceWorker::new(self, script_url.clone(), scope.clone(), worker_id); // Step 2.3 workers.insert(worker_id, Dom::from_ref(&*new_worker)); @@ -975,7 +973,7 @@ impl GlobalScope { { let _ = self .script_to_constellation_chan() - .send(ScriptMsg::RemoveMessagePortRouter(router_id.clone())); + .send(ScriptMsg::RemoveMessagePortRouter(*router_id)); } *self.message_port_state.borrow_mut() = MessagePortState::UnManaged; } @@ -989,7 +987,7 @@ impl GlobalScope { let _ = self.script_to_constellation_chan() .send(ScriptMsg::RemoveBroadcastChannelRouter( - router_id.clone(), + *router_id, self.origin().immutable().clone(), )); } @@ -1008,8 +1006,8 @@ impl GlobalScope { }, Some(managed_port) => { if let Some(port_impl) = managed_port.port_impl.as_mut() { - managed_port.dom_port.entangle(entangled_id.clone()); - port_impl.entangle(entangled_id.clone()); + managed_port.dom_port.entangle(*entangled_id); + port_impl.entangle(*entangled_id); } else { panic!("managed-port has no port-impl."); } @@ -1054,7 +1052,7 @@ impl GlobalScope { port_impl.set_has_been_shipped(); let _ = self .script_to_constellation_chan() - .send(ScriptMsg::MessagePortShipped(port_id.clone())); + .send(ScriptMsg::MessagePortShipped(*port_id)); port_impl } else { panic!("mark_port_as_transferred called on a global not managing any ports."); @@ -1078,7 +1076,7 @@ impl GlobalScope { }; if let Some(message_buffer) = message_buffer { for task in message_buffer { - let port_id = port_id.clone(); + let port_id = *port_id; let this = Trusted::new(self); let _ = self.port_message_queue().queue( task!(process_pending_port_messages: move || { @@ -1172,7 +1170,7 @@ impl GlobalScope { // we could skip the hop to the constellation. let _ = self .script_to_constellation_chan() - .send(ScriptMsg::ScheduleBroadcast(router_id.clone(), msg)); + .send(ScriptMsg::ScheduleBroadcast(*router_id, msg)); } else { panic!("Attemps to broadcast a message via global not managing any channels."); } @@ -1324,7 +1322,7 @@ impl GlobalScope { .iter() .filter_map(|(id, managed_port)| { if managed_port.pending { - Some(id.clone()) + Some(*id) } else { None } @@ -1342,7 +1340,7 @@ impl GlobalScope { let _ = self.script_to_constellation_chan() .send(ScriptMsg::CompleteMessagePortTransfer( - router_id.clone(), + *router_id, to_be_added, )); } else { @@ -1363,8 +1361,8 @@ impl GlobalScope { // and to forward this message to the script-process where the entangled is found. let _ = self .script_to_constellation_chan() - .send(ScriptMsg::RemoveMessagePort(id.clone())); - Some(id.clone()) + .send(ScriptMsg::RemoveMessagePort(*id)); + Some(*id) } else { None } @@ -1394,7 +1392,7 @@ impl GlobalScope { if channels.is_empty() { let _ = self.script_to_constellation_chan().send( ScriptMsg::RemoveBroadcastChannelNameInRouter( - router_id.clone(), + *router_id, name.to_string(), self.origin().immutable().clone(), ), @@ -1442,7 +1440,7 @@ impl GlobalScope { }), ); let router_id = BroadcastChannelRouterId::new(); - *current_state = BroadcastChannelState::Managed(router_id.clone(), HashMap::new()); + *current_state = BroadcastChannelState::Managed(router_id, HashMap::new()); let _ = self .script_to_constellation_chan() .send(ScriptMsg::NewBroadcastChannelRouter( @@ -1456,7 +1454,7 @@ impl GlobalScope { let entry = channels.entry(dom_channel.Name()).or_insert_with(|| { let _ = self.script_to_constellation_chan().send( ScriptMsg::NewBroadcastChannelNameInRouter( - router_id.clone(), + *router_id, dom_channel.Name().to_string(), self.origin().immutable().clone(), ), @@ -1498,8 +1496,7 @@ impl GlobalScope { }), ); let router_id = MessagePortRouterId::new(); - *current_state = - MessagePortState::Managed(router_id.clone(), HashMapTracedValues::new()); + *current_state = MessagePortState::Managed(router_id, HashMapTracedValues::new()); let _ = self .script_to_constellation_chan() .send(ScriptMsg::NewMessagePortRouter( @@ -1514,7 +1511,7 @@ impl GlobalScope { // and only ask the constellation to complete the transfer // if they're not re-shipped in the current task. message_ports.insert( - dom_port.message_port_id().clone(), + *dom_port.message_port_id(), ManagedMessagePort { port_impl: Some(port_impl), dom_port: Dom::from_ref(dom_port), @@ -1535,7 +1532,7 @@ impl GlobalScope { ); } else { // If this is a newly-created port, let the constellation immediately know. - let port_impl = MessagePortImpl::new(dom_port.message_port_id().clone()); + let port_impl = MessagePortImpl::new(*dom_port.message_port_id()); message_ports.insert( *dom_port.message_port_id(), ManagedMessagePort {