Fixed the .clone() warnings. (#31819)

This commit is contained in:
Aarya Khandelwal 2024-03-22 11:11:17 +05:30 committed by GitHub
parent 95e69fe4ff
commit 9b26dca141
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 76 additions and 93 deletions

View file

@ -204,7 +204,7 @@ impl CanvasState {
}
pub fn get_canvas_id(&self) -> CanvasId {
self.canvas_id.clone()
self.canvas_id
}
pub fn send_canvas_2d_msg(&self, msg: Canvas2dMsg) {

View file

@ -1537,7 +1537,7 @@ impl GlobalScope {
// If this is a newly-created port, let the constellation immediately know.
let port_impl = MessagePortImpl::new(dom_port.message_port_id().clone());
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),
@ -1548,8 +1548,8 @@ impl GlobalScope {
let _ = self
.script_to_constellation_chan()
.send(ScriptMsg::NewMessagePort(
router_id.clone(),
dom_port.message_port_id().clone(),
*router_id,
*dom_port.message_port_id(),
));
};
} else {
@ -1674,9 +1674,7 @@ impl GlobalScope {
.get(blob_id)
.expect("get_blob_bytes for an unknown blob.");
match blob_info.blob_impl.blob_data() {
BlobData::Sliced(ref parent, ref rel_pos) => {
Some((parent.clone(), rel_pos.clone()))
},
BlobData::Sliced(ref parent, ref rel_pos) => Some((*parent, rel_pos.clone())),
_ => None,
}
} else {
@ -1739,9 +1737,7 @@ impl GlobalScope {
.get(blob_id)
.expect("get_blob_bytes_or_file_id for an unknown blob.");
match blob_info.blob_impl.blob_data() {
BlobData::Sliced(ref parent, ref rel_pos) => {
Some((parent.clone(), rel_pos.clone()))
},
BlobData::Sliced(ref parent, ref rel_pos) => Some((*parent, rel_pos.clone())),
_ => None,
}
} else {
@ -1811,9 +1807,7 @@ impl GlobalScope {
.get(blob_id)
.expect("get_blob_size called for a unknown blob.");
match blob_info.blob_impl.blob_data() {
BlobData::Sliced(ref parent, ref rel_pos) => {
Some((parent.clone(), rel_pos.clone()))
},
BlobData::Sliced(ref parent, ref rel_pos) => Some((*parent, rel_pos.clone())),
_ => None,
}
};
@ -1857,9 +1851,7 @@ impl GlobalScope {
blob_info.has_url = true;
match blob_info.blob_impl.blob_data() {
BlobData::Sliced(ref parent, ref rel_pos) => {
Some((parent.clone(), rel_pos.clone()))
},
BlobData::Sliced(ref parent, ref rel_pos) => Some((*parent, rel_pos.clone())),
_ => None,
}
};
@ -1904,7 +1896,7 @@ impl GlobalScope {
let (tx, rx) = profile_ipc::channel(self.time_profiler_chan().clone()).unwrap();
let msg = FileManagerThreadMsg::AddSlicedURLEntry(
parent_file_id.clone(),
*parent_file_id,
rel_pos.clone(),
tx,
origin.clone(),
@ -1913,7 +1905,7 @@ impl GlobalScope {
match rx.recv().expect("File manager thread is down.") {
Ok(new_id) => {
*blob_info.blob_impl.blob_data_mut() = BlobData::File(FileBlob::new(
new_id.clone(),
new_id,
None,
None,
rel_pos.to_abs_range(parent_len as usize).len() as u64,
@ -1977,7 +1969,7 @@ impl GlobalScope {
self.send_to_file_manager(msg);
*blob_info.blob_impl.blob_data_mut() = BlobData::File(FileBlob::new(
id.clone(),
id,
None,
Some(bytes.to_vec()),
bytes.len() as u64,
@ -2295,7 +2287,7 @@ impl GlobalScope {
pub fn issue_page_warning(&self, warning: &str) {
if let Some(ref chan) = self.devtools_chan {
let _ = chan.send(ScriptToDevtoolsControlMsg::ReportPageError(
self.pipeline_id.clone(),
self.pipeline_id,
PageError {
type_: "PageError".to_string(),
errorMessage: warning.to_string(),
@ -2483,7 +2475,7 @@ impl GlobalScope {
} else if self.is::<Window>() {
if let Some(ref chan) = self.devtools_chan {
let _ = chan.send(ScriptToDevtoolsControlMsg::ReportPageError(
self.pipeline_id.clone(),
self.pipeline_id,
PageError {
type_: "PageError".to_string(),
errorMessage: error_info.message.clone(),

View file

@ -41,10 +41,10 @@ pub struct WebGPUContextId(pub u64);
impl Clone for GPUCanvasConfiguration {
fn clone(&self) -> Self {
Self {
alphaMode: self.alphaMode.clone(),
alphaMode: self.alphaMode,
device: self.device.clone(),
format: self.format.clone(),
usage: self.usage.clone(),
format: self.format,
usage: self.usage,
viewFormats: self.viewFormats.clone(),
}
}

View file

@ -1698,7 +1698,7 @@ impl VirtualMethods for HTMLFormElement {
.borrow()
.iter()
.filter(|c| !c.is_in_same_home_subtree(self))
.map(|c| c.clone()),
.cloned(),
);
for control in to_reset.iter() {

View file

@ -1411,7 +1411,7 @@ impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> {
}
fn image_density(self) -> Option<f64> {
self.current_request().current_pixel_density.clone()
self.current_request().current_pixel_density
}
fn get_width(self) -> LengthOrPercentageOrAuto {

View file

@ -1357,7 +1357,7 @@ impl HTMLMediaElement {
HTMLMediaElementTypeId::HTMLVideoElement => Some(self.video_renderer.clone()),
};
let audio_renderer = self.audio_renderer.borrow().as_ref().map(|r| r.clone());
let audio_renderer = self.audio_renderer.borrow().as_ref().cloned();
let pipeline_id = window.pipeline_id();
let client_context_id =
@ -2470,7 +2470,7 @@ impl LayoutHTMLMediaElementHelpers for LayoutDom<'_, HTMLMediaElement> {
fn data(self) -> HTMLMediaData {
let media = unsafe { &*self.unsafe_get() };
HTMLMediaData {
current_frame: media.video_renderer.lock().unwrap().current_frame.clone(),
current_frame: media.video_renderer.lock().unwrap().current_frame,
}
}
}

View file

@ -105,7 +105,7 @@ unsafe extern "C" fn off_thread_compilation_callback(
let url = context.url.clone();
let final_url = context.final_url.clone();
let script_element = context.script_element.clone();
let script_kind = context.script_kind.clone();
let script_kind = context.script_kind;
let script = replace(&mut context.script_text, String::new());
let fetch_options = context.fetch_options.clone();
@ -211,7 +211,7 @@ impl HTMLScriptElement {
}
pub fn get_script_id(&self) -> ScriptId {
self.id.clone()
self.id
}
}
@ -402,7 +402,7 @@ impl FetchResponseListener for ClassicContext {
// Step 6, response is an error.
finish_fetching_a_classic_script(
&*self.elem.root(),
self.kind.clone(),
self.kind,
self.url.clone(),
Err(NoTrace(err.clone())),
);
@ -438,7 +438,7 @@ impl FetchResponseListener for ClassicContext {
let context = Box::new(OffThreadCompilationContext {
script_element: self.elem.clone(),
script_kind: self.kind.clone(),
script_kind: self.kind,
final_url,
url: self.url.clone(),
task_source: global.dom_manipulation_task_source(),
@ -464,7 +464,7 @@ impl FetchResponseListener for ClassicContext {
self.fetch_options.clone(),
ScriptType::Classic,
);
finish_fetching_a_classic_script(&*elem, self.kind.clone(), self.url.clone(), Ok(load));
finish_fetching_a_classic_script(&*elem, self.kind, self.url.clone(), Ok(load));
}
}
@ -816,7 +816,7 @@ impl HTMLScriptElement {
Rc::clone(&text_rc),
base_url.clone(),
options.clone(),
script_type.clone(),
script_type,
));
// Step 27-2.
@ -850,7 +850,7 @@ impl HTMLScriptElement {
ModuleOwner::Window(Trusted::new(self)),
text_rc,
base_url.clone(),
self.id.clone(),
self.id,
options,
);
},

View file

@ -40,10 +40,7 @@ impl MessageChannel {
incumbent.track_message_port(&*port2, None);
// Step 3
incumbent.entangle_ports(
port1.message_port_id().clone(),
port2.message_port_id().clone(),
);
incumbent.entangle_ports(*port1.message_port_id(), *port2.message_port_id());
// Steps 4-6
reflect_dom_object_with_proto(

View file

@ -151,7 +151,7 @@ impl MessagePort {
// Have the global proxy this call to the corresponding MessagePortImpl.
self.global()
.post_messageport_msg(self.message_port_id().clone(), task);
.post_messageport_msg(*self.message_port_id(), task);
Ok(())
}
}
@ -176,15 +176,15 @@ impl Transferable for MessagePort {
// 2. Store the transferred object at a given key.
if let Some(ports) = port_impls.as_mut() {
ports.insert(id.clone(), transferred_port);
ports.insert(*id, transferred_port);
} else {
let mut ports = HashMap::new();
ports.insert(id.clone(), transferred_port);
ports.insert(*id, transferred_port);
*port_impls = Some(ports);
}
let PipelineNamespaceId(name_space) = id.clone().namespace_id;
let MessagePortIndex(index) = id.clone().index;
let PipelineNamespaceId(name_space) = (*id).namespace_id;
let MessagePortIndex(index) = (*id).index;
let index = index.get();
let mut big: [u8; 8] = [0; 8];
@ -251,7 +251,7 @@ impl Transferable for MessagePort {
};
let transferred_port =
MessagePort::new_transferred(&*owner, id.clone(), port_impl.entangled_port_id());
MessagePort::new_transferred(&*owner, id, port_impl.entangled_port_id());
owner.track_message_port(&transferred_port, Some(port_impl));
return_object.set(transferred_port.reflector().rootable().get());

View file

@ -80,7 +80,7 @@ impl PerformanceEntryList {
.as_ref()
.map_or(true, |type_| *e.entry_type() == *type_)
})
.map(|e| e.clone())
.cloned()
.collect::<Vec<DomRoot<PerformanceEntry>>>();
res.sort_by(|a, b| {
a.start_time()

View file

@ -109,7 +109,7 @@ impl PerformanceNavigationTimingMethods for PerformanceNavigationTiming {
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-type
fn Type(&self) -> NavigationType {
self.nav_type.clone()
self.nav_type
}
// https://w3c.github.io/navigation-timing/#dom-performancenavigationtiming-redirectcount

View file

@ -186,7 +186,7 @@ impl PerformanceObserverMethods for PerformanceObserver {
let entry_types = entry_types
.iter()
.filter(|e| VALID_ENTRY_TYPES.contains(&e.as_ref()))
.map(|e| e.clone())
.cloned()
.collect::<Vec<DOMString>>();
// Step 6.3

View file

@ -310,7 +310,7 @@ pub fn get_descriptor_permission_state(
.borrow()
.get(&permission_name.to_string())
{
return prev_result.clone();
return *prev_result;
}
// Store the invocation result

View file

@ -208,16 +208,12 @@ impl Request {
// Step 15
if let Some(init_referrerpolicy) = init.referrerPolicy.as_ref() {
let init_referrer_policy = init_referrerpolicy.clone().into();
let init_referrer_policy = (*init_referrerpolicy).into();
request.referrer_policy = Some(init_referrer_policy);
}
// Step 16
let mode = init
.mode
.as_ref()
.map(|m| m.clone().into())
.or(fallback_mode);
let mode = init.mode.as_ref().map(|m| (*m).into()).or(fallback_mode);
// Step 17
if let Some(NetTraitsRequestMode::Navigate) = mode {
@ -231,13 +227,13 @@ impl Request {
// Step 19
if let Some(init_credentials) = init.credentials.as_ref() {
let credentials = init_credentials.clone().into();
let credentials = (*init_credentials).into();
request.credentials_mode = credentials;
}
// Step 20
if let Some(init_cache) = init.cache.as_ref() {
let cache = init_cache.clone().into();
let cache = (*init_cache).into();
request.cache_mode = cache;
}
@ -252,7 +248,7 @@ impl Request {
// Step 22
if let Some(init_redirect) = init.redirect.as_ref() {
let redirect = init_redirect.clone().into();
let redirect = (*init_redirect).into();
request.redirect_mode = redirect;
}

View file

@ -334,8 +334,8 @@ impl ResponseMethods for Response {
// https://fetch.spec.whatwg.org/#concept-response-clone
// Instead of storing a net_traits::Response internally, we
// only store the relevant fields, and only clone them here
*new_response.response_type.borrow_mut() = self.response_type.borrow().clone();
*new_response.status.borrow_mut() = self.status.borrow().clone();
*new_response.response_type.borrow_mut() = *self.response_type.borrow();
*new_response.status.borrow_mut() = *self.status.borrow();
*new_response.raw_status.borrow_mut() = self.raw_status.borrow().clone();
*new_response.url.borrow_mut() = self.url.borrow().clone();
*new_response.url_list.borrow_mut() = self.url_list.borrow().clone();

View file

@ -112,7 +112,7 @@ impl RTCIceCandidateMethods for RTCIceCandidate {
/// <https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-sdpmlineindex>
fn GetSdpMLineIndex(&self) -> Option<u16> {
self.sdp_m_line_index.clone()
self.sdp_m_line_index
}
/// <https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-usernamefragment>
@ -125,7 +125,7 @@ impl RTCIceCandidateMethods for RTCIceCandidate {
RTCIceCandidateInit {
candidate: self.candidate.clone(),
sdpMid: self.sdp_m_id.clone(),
sdpMLineIndex: self.sdp_m_line_index.clone(),
sdpMLineIndex: self.sdp_m_line_index,
usernameFragment: self.username_fragment.clone(),
}
}

View file

@ -1000,7 +1000,7 @@ impl TestBindingMethods for TestBinding {
resolve.map(SimpleHandler::new),
reject.map(SimpleHandler::new),
);
let p = Promise::new_in_current_realm(comp.clone());
let p = Promise::new_in_current_realm(comp);
p.append_native_handler(&handler, comp);
return p;

View file

@ -29,13 +29,13 @@ impl Iterable for TestBindingPairIterable {
self.map.borrow().len() as u32
}
fn get_value_at_index(&self, index: u32) -> u32 {
self.map
*self
.map
.borrow()
.iter()
.nth(index as usize)
.map(|a| &a.1)
.unwrap()
.clone()
}
fn get_key_at_index(&self, index: u32) -> DOMString {
self.map

View file

@ -33,7 +33,7 @@ impl TransitionEvent {
TransitionEvent {
event: Event::new_inherited(),
property_name: Atom::from(init.propertyName.clone()),
elapsed_time: init.elapsedTime.clone(),
elapsed_time: init.elapsedTime,
pseudo_element: init.pseudoElement.clone(),
}
}
@ -88,7 +88,7 @@ impl TransitionEventMethods for TransitionEvent {
// https://drafts.csswg.org/css-transitions/#Events-TransitionEvent-elapsedTime
fn ElapsedTime(&self) -> Finite<f32> {
self.elapsed_time.clone()
self.elapsed_time
}
// https://drafts.csswg.org/css-transitions/#Events-TransitionEvent-pseudoElement

View file

@ -235,7 +235,7 @@ impl WebGLRenderbuffer {
),
);
let samples = receiver.recv().unwrap();
if sample_count < 0 || sample_count > samples.get(0).cloned().unwrap_or(0) {
if sample_count < 0 || sample_count > samples.first().cloned().unwrap_or(0) {
return Err(WebGLError::InvalidOperation);
}
}

View file

@ -2329,7 +2329,7 @@ impl Window {
}
pub fn set_page_clip_rect_with_new_viewport(&self, viewport: UntypedRect<f32>) -> bool {
let rect = f32_rect_to_au_rect(viewport.clone());
let rect = f32_rect_to_au_rect(viewport);
self.current_viewport.set(rect);
// We use a clipping rectangle that is five times the size of the of the viewport,
// so that we don't collect display list items for areas too far outside the viewport,

View file

@ -220,7 +220,7 @@ impl WorkerGlobalScope {
}
pub fn get_worker_id(&self) -> WorkerId {
self.worker_id.clone()
self.worker_id
}
pub fn task_canceller(&self) -> TaskCanceller {

View file

@ -153,7 +153,7 @@ impl WorkletMethods for Worklet {
self.window.origin().immutable().clone(),
global.api_base_url(),
module_url_record,
options.credentials.clone(),
options.credentials,
pending_tasks_struct,
&promise,
);

View file

@ -720,7 +720,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
.credentials_mode(credentials_mode)
.use_url_credentials(use_url_credentials)
.origin(self.global().origin().immutable().clone())
.referrer_policy(self.referrer_policy.clone())
.referrer_policy(self.referrer_policy)
.pipeline_id(Some(self.global().pipeline_id()));
// step 4 (second half)

View file

@ -731,7 +731,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ThreadSafeLayoutElement<'dom>
fn as_node(&self) -> ServoThreadSafeLayoutNode<'dom, LayoutDataType> {
ServoThreadSafeLayoutNode {
node: self.element.as_node(),
pseudo: self.pseudo.clone(),
pseudo: self.pseudo,
}
}
@ -741,7 +741,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ThreadSafeLayoutElement<'dom>
fn with_pseudo(&self, pseudo: PseudoElementType) -> Self {
ServoThreadSafeLayoutElement {
element: self.element.clone(),
element: self.element,
pseudo,
}
}

View file

@ -285,7 +285,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ServoThreadSafeLayoutNode<'dom, Layo
/// Creates a new `ServoThreadSafeLayoutNode` from the given `ServoLayoutNode`.
pub fn new(node: ServoLayoutNode<'dom, LayoutDataType>) -> Self {
ServoThreadSafeLayoutNode {
node: node.clone(),
node: node,
pseudo: PseudoElementType::Normal,
}
}
@ -529,7 +529,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> Iterator
PseudoElementType::Before | PseudoElementType::After => None,
PseudoElementType::DetailsSummary => {
let mut current_node = self.current_node.clone();
let mut current_node = self.current_node;
loop {
let next_node = if let Some(ref node) = current_node {
if let Some(element) = node.as_element() {
@ -537,7 +537,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> Iterator
element.has_namespace(&ns!(html))
{
self.current_node = None;
return Some(node.clone());
return Some(*node);
}
}
unsafe { node.dangerous_next_sibling() }
@ -550,7 +550,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> Iterator
},
PseudoElementType::DetailsContent => {
let node = self.current_node.clone();
let node = self.current_node;
let node = node.and_then(|node| {
if node.is_element() &&
node.as_element()
@ -568,7 +568,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> Iterator
},
PseudoElementType::Normal => {
let node = self.current_node.clone();
let node = self.current_node;
if let Some(ref node) = node {
self.current_node = match node.get_pseudo_element_type() {
PseudoElementType::Before => self

View file

@ -105,9 +105,7 @@ impl RethrowError {
impl Clone for RethrowError {
fn clone(&self) -> Self {
Self(RootedTraceableBox::from_box(Heap::boxed(
self.0.get().clone(),
)))
Self(RootedTraceableBox::from_box(Heap::boxed(self.0.get())))
}
}
@ -212,7 +210,7 @@ impl ModuleTree {
}
pub fn get_status(&self) -> ModuleStatus {
self.status.borrow().clone()
*self.status.borrow()
}
pub fn set_status(&self, status: ModuleStatus) {
@ -771,7 +769,7 @@ impl ModuleTree {
owner.clone(),
url.clone(),
visited_urls.clone(),
destination.clone(),
destination,
options,
Some(parent_identity.clone()),
false,
@ -1164,7 +1162,7 @@ impl FetchResponseListener for ModuleContext {
module_tree.fetch_module_descendants(
&self.owner,
self.destination.clone(),
self.destination,
&self.options,
ModuleIdentity::ModuleUrl(self.url.clone()),
);
@ -1355,7 +1353,7 @@ fn fetch_an_import_module_script_graph(
_ => ModuleOwner::DynamicModule(Trusted::new(&DynamicModuleOwner::new(
global,
promise.clone(),
dynamic_module_id.clone(),
dynamic_module_id,
))),
};
@ -1634,7 +1632,7 @@ fn fetch_single_module_script(
global.set_module_map(url.clone(), module_tree);
// Step 5-6.
let mode = match destination.clone() {
let mode = match destination {
Destination::Worker | Destination::SharedWorker if top_level_module_fetch => {
RequestMode::SameOrigin
},
@ -1648,7 +1646,7 @@ fn fetch_single_module_script(
// Step 7-8.
let request = RequestBuilder::new(url.clone(), global.get_referrer())
.destination(destination.clone())
.destination(destination)
.origin(global.origin().immutable().clone())
.parser_metadata(options.parser_metadata)
.integrity_metadata(options.integrity_metadata.clone())
@ -1660,7 +1658,7 @@ fn fetch_single_module_script(
data: vec![],
metadata: None,
url: url.clone(),
destination: destination.clone(),
destination: destination,
options,
status: Ok(()),
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource),
@ -1723,7 +1721,7 @@ pub(crate) fn fetch_inline_module_script(
Ok(record) => {
module_tree.append_handler(
owner.clone(),
ModuleIdentity::ScriptId(script_id.clone()),
ModuleIdentity::ScriptId(script_id),
options.clone(),
);
module_tree.set_record(record);
@ -1749,7 +1747,7 @@ pub(crate) fn fetch_inline_module_script(
Err(exception) => {
module_tree.set_rethrow_error(exception);
module_tree.set_status(ModuleStatus::Finished);
global.set_inline_module_map(script_id.clone(), module_tree);
global.set_inline_module_map(script_id, module_tree);
owner.notify_owner_to_finish(ModuleIdentity::ScriptId(script_id), options);
},
}

View file

@ -2788,7 +2788,7 @@ impl ScriptThread {
..
}) => {
// If we have an existing window that is being navigated:
if let Some(window) = self.documents.borrow().find_window(id.clone()) {
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
@ -3817,7 +3817,7 @@ impl ScriptThread {
/// Instructs the constellation to fetch the document that will be loaded. Stores the InProgressLoad
/// argument until a notification is received that the fetch is complete.
fn pre_page_load(&self, mut incomplete: InProgressLoad, load_data: LoadData) {
let id = incomplete.pipeline_id.clone();
let id = incomplete.pipeline_id;
let req_init = RequestBuilder::new(load_data.url.clone(), load_data.referrer)
.method(load_data.method)
.destination(Destination::Document)