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

@ -242,7 +242,7 @@ pub fn main() {
if args.system_specs {
let system_specs = feedback::system_specs::SystemSpecs::new_stateless(
app_version,
app_commit_sha.clone(),
app_commit_sha,
*release_channel::RELEASE_CHANNEL,
);
println!("Zed System Specs (from CLI):\n{}", system_specs);
@ -367,7 +367,7 @@ pub fn main() {
if let Some(app_state) = AppState::try_global(cx).and_then(|app_state| app_state.upgrade())
{
cx.spawn({
let app_state = app_state.clone();
let app_state = app_state;
async move |cx| {
if let Err(e) = restore_or_create_workspace(app_state, cx).await {
fail_to_open_window_async(e, cx)
@ -523,13 +523,13 @@ pub fn main() {
let app_session = cx.new(|cx| AppSession::new(session, cx));
let app_state = Arc::new(AppState {
languages: languages.clone(),
languages,
client: client.clone(),
user_store: user_store.clone(),
user_store,
fs: fs.clone(),
build_window_options,
workspace_store,
node_runtime: node_runtime.clone(),
node_runtime,
session: app_session,
});
AppState::set_global(Arc::downgrade(&app_state), cx);
@ -751,7 +751,6 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
if let Some(kind) = request.kind {
match kind {
OpenRequestKind::CliConnection(connection) => {
let app_state = app_state.clone();
cx.spawn(async move |cx| handle_cli_connection(connection, app_state, cx).await)
.detach();
}
@ -1313,7 +1312,6 @@ fn eager_load_active_theme_and_icon_theme(fs: Arc<dyn Fs>, cx: &App) {
.path_to_extension_icon_theme(icon_theme_name)
{
cx.spawn({
let theme_registry = theme_registry.clone();
let fs = fs.clone();
async move |cx| {
theme_registry
@ -1335,9 +1333,7 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut App) {
cx.spawn({
let fs = fs.clone();
async move |cx| {
if let Some(theme_registry) =
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
{
if let Some(theme_registry) = cx.update(|cx| ThemeRegistry::global(cx)).log_err() {
let themes_dir = paths::themes_dir().as_ref();
match fs
.metadata(themes_dir)
@ -1376,7 +1372,7 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut App) {
for event in paths {
if fs.metadata(&event.path).await.ok().flatten().is_some()
&& let Some(theme_registry) =
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
cx.update(|cx| ThemeRegistry::global(cx)).log_err()
&& let Some(()) = theme_registry
.load_user_theme(&event.path, fs.clone())
.await

View file

@ -526,8 +526,6 @@ fn initialize_panels(
window: &mut Window,
cx: &mut Context<Workspace>,
) {
let prompt_builder = prompt_builder.clone();
cx.spawn_in(window, async move |workspace_handle, cx| {
let project_panel = ProjectPanel::load(workspace_handle.clone(), cx.clone());
let outline_panel = OutlinePanel::load(workspace_handle.clone(), cx.clone());
@ -1394,7 +1392,7 @@ fn show_keymap_file_load_error(
cx: &mut App,
) {
show_markdown_app_notification(
notification_id.clone(),
notification_id,
error_message,
"Open Keymap File".into(),
|window, cx| {
@ -4786,7 +4784,7 @@ mod tests {
cx.background_executor.run_until_parked();
// 5. Critical: Verify .zed is actually excluded from worktree
let worktree = cx.update(|cx| project.read(cx).worktrees(cx).next().unwrap().clone());
let worktree = cx.update(|cx| project.read(cx).worktrees(cx).next().unwrap());
let has_zed_entry = cx.update(|cx| worktree.read(cx).entry_for_path(".zed").is_some());
@ -4822,7 +4820,7 @@ mod tests {
.await
.unwrap();
let new_content_str = new_content.clone();
let new_content_str = new_content;
eprintln!("New settings content: {}", new_content_str);
// The bug causes the settings to be overwritten with empty settings

View file

@ -33,8 +33,6 @@ use workspace::{
pub fn init(app_state: Arc<AppState>, cx: &mut App) {
workspace::register_serializable_item::<ComponentPreview>(cx);
let app_state = app_state.clone();
cx.observe_new(move |workspace: &mut Workspace, _window, cx| {
let app_state = app_state.clone();
let project = workspace.project().clone();
@ -462,12 +460,12 @@ impl ComponentPreview {
Vec::new()
};
if valid_positions.is_empty() {
Label::new(name.clone()).into_any_element()
Label::new(name).into_any_element()
} else {
HighlightedLabel::new(name.clone(), valid_positions).into_any_element()
HighlightedLabel::new(name, valid_positions).into_any_element()
}
} else {
Label::new(name.clone()).into_any_element()
Label::new(name).into_any_element()
})
.selectable(true)
.toggle_state(selected)
@ -685,7 +683,7 @@ impl ComponentPreview {
.h_full()
.py_8()
.bg(cx.theme().colors().panel_background)
.children(self.active_thread.clone().map(|thread| thread.clone()))
.children(self.active_thread.clone())
.when_none(&self.active_thread.clone(), |this| {
this.child("No active thread")
}),
@ -716,7 +714,7 @@ impl Render for ComponentPreview {
if input.is_empty(cx) {
String::new()
} else {
input.editor().read(cx).text(cx).to_string()
input.editor().read(cx).text(cx)
}
});
@ -929,7 +927,7 @@ impl SerializableItem for ComponentPreview {
Err(_) => ActivePageId::default(),
};
let user_store = project.read(cx).user_store().clone();
let user_store = project.read(cx).user_store();
let language_registry = project.read(cx).languages().clone();
let preview_page = if deserialized_active_page.0 == ActivePageId::default().0 {
Some(PreviewPage::default())
@ -940,7 +938,7 @@ impl SerializableItem for ComponentPreview {
let found_component = all_components.iter().find(|c| c.id().0 == component_str);
if let Some(component) = found_component {
Some(PreviewPage::Component(component.id().clone()))
Some(PreviewPage::Component(component.id()))
} else {
Some(PreviewPage::default())
}
@ -1057,7 +1055,7 @@ impl ComponentPreviewPage {
.rounded_sm()
.bg(color.color(cx).alpha(0.12))
.child(
Label::new(status.clone().to_string())
Label::new(status.to_string())
.size(LabelSize::Small)
.color(color),
),

View file

@ -60,23 +60,16 @@ pub fn init(client: Arc<Client>, user_store: Entity<UserStore>, cx: &mut App) {
cx.subscribe(&user_store, {
let editors = editors.clone();
let client = client.clone();
move |user_store, event, cx| {
if let client::user::Event::PrivateUserInfoUpdated = event {
assign_edit_prediction_providers(
&editors,
provider,
&client,
user_store.clone(),
cx,
);
assign_edit_prediction_providers(&editors, provider, &client, user_store, cx);
}
}
})
.detach();
cx.observe_global::<SettingsStore>({
let editors = editors.clone();
let client = client.clone();
let user_store = user_store.clone();
move |cx| {
let new_provider = all_language_settings(None, cx).edit_predictions.provider;

View file

@ -102,11 +102,8 @@ impl OpenRequest {
self.open_paths.is_empty(),
"cannot open both local and ssh paths"
);
let mut connection_options = SshSettings::get_global(cx).connection_options_for(
host.clone(),
port,
username.clone(),
);
let mut connection_options =
SshSettings::get_global(cx).connection_options_for(host, port, username);
if let Some(password) = url.password() {
connection_options.password = Some(password.to_string());
}

View file

@ -161,7 +161,7 @@ impl Render for QuickActionBar {
IconName::ZedAssistant,
false,
Box::new(InlineAssist::default()),
focus_handle.clone(),
focus_handle,
"Inline Assist",
move |_, window, cx| {
window.dispatch_action(Box::new(InlineAssist::default()), cx);
@ -215,7 +215,7 @@ impl Render for QuickActionBar {
)
})
.on_click({
let focus = focus.clone();
let focus = focus;
move |_, window, cx| {
focus.dispatch_action(
&ToggleCodeActions {

View file

@ -196,7 +196,6 @@ impl QuickActionBar {
.into_any_element()
},
{
let editor = editor.clone();
move |window, cx| {
repl::restart(editor.clone(), window, cx);
}
@ -346,7 +345,7 @@ impl QuickActionBar {
),
Tooltip::text("Select Kernel"),
)
.with_handle(menu_handle.clone())
.with_handle(menu_handle)
.into_any_element()
}
@ -362,7 +361,7 @@ impl QuickActionBar {
.shape(ui::IconButtonShape::Square)
.icon_size(ui::IconSize::Small)
.icon_color(Color::Muted)
.tooltip(Tooltip::text(tooltip.clone()))
.tooltip(Tooltip::text(tooltip))
.on_click(|_, _window, cx| {
cx.open_url(&format!("{}#installation", ZED_REPL_DOCUMENTATION))
}),