Fix clippy::redundant_clone lint violations (#36558)

This removes around 900 unnecessary clones, ranging from cloning a few
ints all the way to large data structures and images.

A lot of these were fixed using `cargo clippy --fix --workspace
--all-targets`, however it often breaks other lints and needs to be run
again. This was then followed up with some manual fixing.

I understand this is a large diff, but all the changes are pretty
trivial. Rust is doing some heavy lifting here for us. Once I get it up
to speed with main, I'd appreciate this getting merged rather sooner
than later.

Release Notes:

- N/A
This commit is contained in:
tidely 2025-08-20 13:20:13 +03:00 committed by GitHub
parent cf7c64d77f
commit 7bdc99abc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
306 changed files with 805 additions and 1102 deletions

View file

@ -171,7 +171,7 @@ where
}
fn panel_focus_handle(&self, cx: &App) -> FocusHandle {
self.read(cx).focus_handle(cx).clone()
self.read(cx).focus_handle(cx)
}
fn activation_priority(&self, cx: &App) -> u32 {
@ -340,7 +340,7 @@ impl Dock {
pub fn panel<T: Panel>(&self) -> Option<Entity<T>> {
self.panel_entries
.iter()
.find_map(|entry| entry.panel.to_any().clone().downcast().ok())
.find_map(|entry| entry.panel.to_any().downcast().ok())
}
pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {

View file

@ -1012,7 +1012,6 @@ where
let message: SharedString = format!("Error: {err}").into();
log::error!("Showing error notification in app: {message}");
show_app_notification(workspace_error_notification_id(), cx, {
let message = message.clone();
move |cx| {
cx.new({
let message = message.clone();

View file

@ -480,7 +480,7 @@ impl Pane {
forward_stack: Default::default(),
closed_stack: Default::default(),
paths_by_item: Default::default(),
pane: handle.clone(),
pane: handle,
next_timestamp,
}))),
toolbar: cx.new(|_| Toolbar::new()),
@ -2516,7 +2516,7 @@ impl Pane {
this.handle_external_paths_drop(paths, window, cx)
}))
.when_some(item.tab_tooltip_content(cx), |tab, content| match content {
TabTooltipContent::Text(text) => tab.tooltip(Tooltip::text(text.clone())),
TabTooltipContent::Text(text) => tab.tooltip(Tooltip::text(text)),
TabTooltipContent::Custom(element_fn) => {
tab.tooltip(move |window, cx| element_fn(window, cx))
}

View file

@ -1175,7 +1175,7 @@ mod element {
bounding_boxes.clear();
let mut layout = PaneAxisLayout {
dragged_handle: dragged_handle.clone(),
dragged_handle,
children: Vec::new(),
};
for (ix, mut child) in mem::take(&mut self.children).into_iter().enumerate() {

View file

@ -620,7 +620,7 @@ mod tests {
]);
let order = vec![2, 0, 1];
let serialized =
SerializedWorkspaceLocation::Local(LocalPaths(paths.clone()), LocalPathsOrder(order));
SerializedWorkspaceLocation::Local(LocalPaths(paths), LocalPathsOrder(order));
assert_eq!(
serialized.sorted_paths(),
Arc::new(vec![

View file

@ -371,13 +371,13 @@ impl<T: SearchableItem> SearchableItemHandle for Entity<T> {
impl From<Box<dyn SearchableItemHandle>> for AnyView {
fn from(this: Box<dyn SearchableItemHandle>) -> Self {
this.to_any().clone()
this.to_any()
}
}
impl From<&Box<dyn SearchableItemHandle>> for AnyView {
fn from(this: &Box<dyn SearchableItemHandle>) -> Self {
this.to_any().clone()
this.to_any()
}
}

View file

@ -108,7 +108,7 @@ impl StatusBar {
self.left_items
.iter()
.chain(self.right_items.iter())
.find_map(|item| item.to_any().clone().downcast().log_err())
.find_map(|item| item.to_any().downcast().log_err())
}
pub fn position_of_item<T>(&self) -> Option<usize>
@ -217,6 +217,6 @@ impl<T: StatusItemView> StatusItemViewHandle for Entity<T> {
impl From<&dyn StatusItemViewHandle> for AnyView {
fn from(val: &dyn StatusItemViewHandle) -> Self {
val.to_any().clone()
val.to_any()
}
}

View file

@ -303,7 +303,6 @@ impl ThemePreview {
.gap_1()
.children(all_colors.into_iter().map(|(color, name)| {
let id = ElementId::Name(format!("{:?}-preview", color).into());
let name = name.clone();
div().size_8().flex_none().child(
ButtonLike::new(id)
.child(

View file

@ -903,7 +903,7 @@ impl AppState {
let languages = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
let clock = Arc::new(clock::FakeSystemClock::new());
let http_client = http_client::FakeHttpClient::with_404_response();
let client = Client::new(clock, http_client.clone(), cx);
let client = Client::new(clock, http_client, cx);
let session = cx.new(|cx| AppSession::new(Session::test(), cx));
let user_store = cx.new(|cx| UserStore::new(client.clone(), cx));
let workspace_store = cx.new(|cx| WorkspaceStore::new(client.clone(), cx));
@ -1323,7 +1323,6 @@ impl Workspace {
let mut active_call = None;
if let Some(call) = ActiveCall::try_global(cx) {
let call = call.clone();
let subscriptions = vec![cx.subscribe_in(&call, window, Self::on_active_call_event)];
active_call = Some((call, subscriptions));
}
@ -4116,7 +4115,6 @@ impl Workspace {
.unwrap_or_else(|| {
self.split_pane(self.active_pane.clone(), SplitDirection::Right, window, cx)
})
.clone()
}
pub fn pane_for(&self, handle: &dyn ItemHandle) -> Option<Entity<Pane>> {
@ -6713,7 +6711,7 @@ impl WorkspaceStore {
.update(cx, |workspace, window, cx| {
let handler_response =
workspace.handle_follow(follower.project_id, window, cx);
if let Some(active_view) = handler_response.active_view.clone()
if let Some(active_view) = handler_response.active_view
&& workspace.project.read(cx).remote_id() == follower.project_id
{
response.active_view = Some(active_view)