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

@ -386,10 +386,10 @@ impl DebugPanel {
return;
};
let dap_store_handle = self.project.read(cx).dap_store().clone();
let dap_store_handle = self.project.read(cx).dap_store();
let label = curr_session.read(cx).label();
let quirks = curr_session.read(cx).quirks();
let adapter = curr_session.read(cx).adapter().clone();
let adapter = curr_session.read(cx).adapter();
let binary = curr_session.read(cx).binary().cloned().unwrap();
let task_context = curr_session.read(cx).task_context().clone();
@ -447,9 +447,9 @@ impl DebugPanel {
return;
};
let dap_store_handle = self.project.read(cx).dap_store().clone();
let dap_store_handle = self.project.read(cx).dap_store();
let label = self.label_for_child_session(&parent_session, request, cx);
let adapter = parent_session.read(cx).adapter().clone();
let adapter = parent_session.read(cx).adapter();
let quirks = parent_session.read(cx).quirks();
let Some(mut binary) = parent_session.read(cx).binary().cloned() else {
log::error!("Attempted to start a child-session without a binary");
@ -932,7 +932,6 @@ impl DebugPanel {
.cloned(),
|this, running_state| {
this.children({
let running_state = running_state.clone();
let threads =
running_state.update(cx, |running_state, cx| {
let session = running_state.session();
@ -1645,7 +1644,6 @@ impl Render for DebugPanel {
}
})
.on_action({
let this = this.clone();
move |_: &ToggleSessionPicker, window, cx| {
this.update(cx, |this, cx| {
this.toggle_session_picker(window, cx);

View file

@ -272,7 +272,6 @@ pub fn init(cx: &mut App) {
}
})
.on_action({
let active_item = active_item.clone();
move |_: &ToggleIgnoreBreakpoints, _, cx| {
active_item
.update(cx, |item, cx| item.toggle_ignore_breakpoints(cx))
@ -293,9 +292,8 @@ pub fn init(cx: &mut App) {
let Some(debug_panel) = workspace.read(cx).panel::<DebugPanel>(cx) else {
return;
};
let Some(active_session) = debug_panel
.clone()
.update(cx, |panel, _| panel.active_session())
let Some(active_session) =
debug_panel.update(cx, |panel, _| panel.active_session())
else {
return;
};

View file

@ -272,10 +272,9 @@ impl DebugPanel {
.child(session_entry.label_element(self_depth, cx))
.child(
IconButton::new("close-debug-session", IconName::Close)
.visible_on_hover(id.clone())
.visible_on_hover(id)
.icon_size(IconSize::Small)
.on_click({
let weak = weak.clone();
move |_, window, cx| {
weak.update(cx, |panel, cx| {
panel.close_session(session_entity_id, window, cx);

View file

@ -785,7 +785,7 @@ impl RenderOnce for AttachMode {
v_flex()
.w_full()
.track_focus(&self.attach_picker.focus_handle(cx))
.child(self.attach_picker.clone())
.child(self.attach_picker)
}
}

View file

@ -256,7 +256,7 @@ pub(crate) fn deserialize_pane_layout(
Some(Member::Axis(PaneAxis::load(
if should_invert { axis.invert() } else { axis },
members,
flexes.clone(),
flexes,
)))
}
SerializedPaneLayout::Pane(serialized_pane) => {

View file

@ -180,7 +180,7 @@ impl SubView {
let weak_list = list.downgrade();
let focus_handle = list.focus_handle(cx);
let this = Self::new(
focus_handle.clone(),
focus_handle,
list.into(),
DebuggerPaneItem::BreakpointList,
cx,
@ -1167,9 +1167,9 @@ impl RunningState {
id: task::TaskId("debug".to_string()),
full_label: title.clone(),
label: title.clone(),
command: command.clone(),
command,
args,
command_label: title.clone(),
command_label: title,
cwd,
env: envs,
use_new_terminal: true,
@ -1756,7 +1756,7 @@ impl RunningState {
this.activate_item(0, false, false, window, cx);
});
let rightmost_pane = new_debugger_pane(workspace.clone(), project.clone(), window, cx);
let rightmost_pane = new_debugger_pane(workspace.clone(), project, window, cx);
rightmost_pane.update(cx, |this, cx| {
this.add_item(
Box::new(SubView::new(

View file

@ -685,7 +685,6 @@ impl BreakpointList {
selection_kind.map(|kind| kind.0) != Some(SelectedBreakpointKind::Source),
)
.on_click({
let focus_handle = focus_handle.clone();
move |_, window, cx| {
focus_handle.focus(window);
window.dispatch_action(UnsetBreakpoint.boxed_clone(), cx)
@ -1139,7 +1138,6 @@ impl ExceptionBreakpoint {
}
})
.on_click({
let list = list.clone();
move |_, _, cx| {
list.update(cx, |this, cx| {
this.toggle_exception_breakpoint(&id, cx);

View file

@ -365,7 +365,7 @@ impl Console {
Some(ContextMenu::build(window, cx, |context_menu, _, _| {
context_menu
.when_some(keybinding_target.clone(), |el, keybinding_target| {
el.context(keybinding_target.clone())
el.context(keybinding_target)
})
.action("Watch Expression", WatchExpression.boxed_clone())
}))

View file

@ -57,7 +57,7 @@ impl LoadedSourceList {
h_flex()
.text_ui_xs(cx)
.text_color(cx.theme().colors().text_muted)
.when_some(source.path.clone(), |this, path| this.child(path)),
.when_some(source.path, |this, path| this.child(path)),
)
.into_any()
}

View file

@ -461,7 +461,7 @@ impl MemoryView {
let data_breakpoint_info = this.data_breakpoint_info(context.clone(), None, cx);
cx.spawn(async move |this, cx| {
if let Some(info) = data_breakpoint_info.await {
let Some(data_id) = info.data_id.clone() else {
let Some(data_id) = info.data_id else {
return;
};
_ = this.update(cx, |this, cx| {

View file

@ -157,7 +157,7 @@ impl ModuleList {
h_flex()
.text_ui_xs(cx)
.text_color(cx.theme().colors().text_muted)
.when_some(module.path.clone(), |this, path| this.child(path)),
.when_some(module.path, |this, path| this.child(path)),
)
.into_any()
}

View file

@ -126,7 +126,7 @@ impl StackFrameList {
self.stack_frames(cx)
.unwrap_or_default()
.into_iter()
.map(|stack_frame| stack_frame.dap.clone())
.map(|stack_frame| stack_frame.dap)
.collect()
}
@ -224,7 +224,7 @@ impl StackFrameList {
let collapsed_entries = std::mem::take(&mut collapsed_entries);
if !collapsed_entries.is_empty() {
entries.push(StackFrameEntry::Collapsed(collapsed_entries.clone()));
entries.push(StackFrameEntry::Collapsed(collapsed_entries));
}
self.entries = entries;
@ -418,7 +418,7 @@ impl StackFrameList {
let source = stack_frame.source.clone();
let is_selected_frame = Some(ix) == self.selected_ix;
let path = source.clone().and_then(|s| s.path.or(s.name));
let path = source.and_then(|s| s.path.or(s.name));
let formatted_path = path.map(|path| format!("{}:{}", path, stack_frame.line,));
let formatted_path = formatted_path.map(|path| {
Label::new(path)

View file

@ -313,7 +313,7 @@ impl VariableList {
watcher.variables_reference,
watcher.variables_reference,
EntryPath::for_watcher(watcher.expression.clone()),
DapEntry::Watcher(watcher.clone()),
DapEntry::Watcher(watcher),
)
})
.collect::<Vec<_>>(),
@ -1301,8 +1301,6 @@ impl VariableList {
IconName::Close,
)
.on_click({
let weak = weak.clone();
let path = path.clone();
move |_, window, cx| {
weak.update(cx, |variable_list, cx| {
variable_list.selection = Some(path.clone());
@ -1470,7 +1468,6 @@ impl VariableList {
}))
})
.on_secondary_mouse_down(cx.listener({
let path = path.clone();
let entry = variable.clone();
move |this, event: &MouseDownEvent, window, cx| {
this.selection = Some(path.clone());

View file

@ -1330,7 +1330,6 @@ async fn test_unsetting_breakpoints_on_clear_breakpoint_action(
let called_set_breakpoints = Arc::new(AtomicBool::new(false));
client.on_request::<SetBreakpoints, _>({
let called_set_breakpoints = called_set_breakpoints.clone();
move |_, args| {
assert!(
args.breakpoints.is_none_or(|bps| bps.is_empty()),
@ -1445,7 +1444,6 @@ async fn test_we_send_arguments_from_user_config(
let launch_handler_called = Arc::new(AtomicBool::new(false));
start_debug_session_with(&workspace, cx, debug_definition.clone(), {
let debug_definition = debug_definition.clone();
let launch_handler_called = launch_handler_called.clone();
move |client| {
@ -1783,9 +1781,8 @@ async fn test_debug_adapters_shutdown_on_app_quit(
let disconnect_request_received = Arc::new(AtomicBool::new(false));
let disconnect_clone = disconnect_request_received.clone();
let disconnect_clone_for_handler = disconnect_clone.clone();
client.on_request::<Disconnect, _>(move |_, _| {
disconnect_clone_for_handler.store(true, Ordering::SeqCst);
disconnect_clone.store(true, Ordering::SeqCst);
Ok(())
});

View file

@ -106,9 +106,7 @@ async fn test_debug_session_substitutes_variables_and_relativizes_paths(
);
let expected_other_field = if input_path.contains("$ZED_WORKTREE_ROOT") {
input_path
.replace("$ZED_WORKTREE_ROOT", path!("/test/worktree/path"))
.to_owned()
input_path.replace("$ZED_WORKTREE_ROOT", path!("/test/worktree/path"))
} else {
input_path.to_string()
};