Fix iterator related clippy style lint violations (#36437)

tidely created

Release Notes:

- N/A

Change summary

Cargo.toml                                              |  5 +++++
crates/agent_ui/src/agent_diff.rs                       |  3 +--
crates/agent_ui/src/message_editor.rs                   |  6 +-----
crates/agent_ui/src/text_thread_editor.rs               |  6 +-----
crates/debugger_ui/src/session/running/variable_list.rs |  2 +-
crates/editor/src/editor.rs                             |  2 +-
crates/git_ui/src/git_panel.rs                          | 10 +++++-----
crates/git_ui/src/project_diff.rs                       |  2 +-
crates/language/src/proto.rs                            |  2 +-
crates/language_tools/src/key_context_view.rs           |  4 +---
crates/settings_ui/src/keybindings.rs                   |  8 +-------
crates/title_bar/src/collab.rs                          |  2 +-
crates/vim/src/normal.rs                                |  2 +-
13 files changed, 21 insertions(+), 33 deletions(-)

Detailed changes

Cargo.toml 🔗

@@ -820,6 +820,11 @@ single_range_in_vec_init = "allow"
 style = { level = "allow", priority = -1 }
 
 # Temporary list of style lints that we've fixed so far.
+iter_cloned_collect = "warn"
+iter_next_slice = "warn"
+iter_nth = "warn"
+iter_nth_zero = "warn"
+iter_skip_next = "warn"
 module_inception = { level = "deny" }
 question_mark = { level = "deny" }
 redundant_closure = { level = "deny" }

crates/agent_ui/src/agent_diff.rs 🔗

@@ -503,8 +503,7 @@ fn update_editor_selection(
                         &[last_kept_hunk_end..editor::Anchor::max()],
                         buffer_snapshot,
                     )
-                    .skip(1)
-                    .next()
+                    .nth(1)
             })
             .or_else(|| {
                 let first_kept_hunk = diff_hunks.first()?;

crates/agent_ui/src/message_editor.rs 🔗

@@ -690,11 +690,7 @@ impl MessageEditor {
             .as_ref()
             .map(|model| {
                 self.incompatible_tools_state.update(cx, |state, cx| {
-                    state
-                        .incompatible_tools(&model.model, cx)
-                        .iter()
-                        .cloned()
-                        .collect::<Vec<_>>()
+                    state.incompatible_tools(&model.model, cx).to_vec()
                 })
             })
             .unwrap_or_default();

crates/agent_ui/src/text_thread_editor.rs 🔗

@@ -747,11 +747,7 @@ impl TextThreadEditor {
             self.context.read(cx).invoked_slash_command(&command_id)
         {
             if let InvokedSlashCommandStatus::Finished = invoked_slash_command.status {
-                let run_commands_in_ranges = invoked_slash_command
-                    .run_commands_in_ranges
-                    .iter()
-                    .cloned()
-                    .collect::<Vec<_>>();
+                let run_commands_in_ranges = invoked_slash_command.run_commands_in_ranges.clone();
                 for range in run_commands_in_ranges {
                     let commands = self.context.update(cx, |context, cx| {
                         context.reparse(cx);

crates/debugger_ui/src/session/running/variable_list.rs 🔗

@@ -272,7 +272,7 @@ impl VariableList {
         let mut entries = vec![];
 
         let scopes: Vec<_> = self.session.update(cx, |session, cx| {
-            session.scopes(stack_frame_id, cx).iter().cloned().collect()
+            session.scopes(stack_frame_id, cx).to_vec()
         });
 
         let mut contains_local_scope = false;

crates/editor/src/editor.rs 🔗

@@ -20932,7 +20932,7 @@ impl Editor {
 
         let existing_pending = self
             .text_highlights::<PendingInput>(cx)
-            .map(|(_, ranges)| ranges.iter().cloned().collect::<Vec<_>>());
+            .map(|(_, ranges)| ranges.to_vec());
         if existing_pending.is_none() && pending.is_empty() {
             return;
         }

crates/git_ui/src/git_panel.rs 🔗

@@ -2756,7 +2756,7 @@ impl GitPanel {
         for pending in self.pending.iter() {
             if pending.target_status == TargetStatus::Staged {
                 pending_staged_count += pending.entries.len();
-                last_pending_staged = pending.entries.iter().next().cloned();
+                last_pending_staged = pending.entries.first().cloned();
             }
             if let Some(single_staged) = &single_staged_entry {
                 if pending
@@ -5261,7 +5261,7 @@ mod tests {
             project
                 .read(cx)
                 .worktrees(cx)
-                .nth(0)
+                .next()
                 .unwrap()
                 .read(cx)
                 .as_local()
@@ -5386,7 +5386,7 @@ mod tests {
             project
                 .read(cx)
                 .worktrees(cx)
-                .nth(0)
+                .next()
                 .unwrap()
                 .read(cx)
                 .as_local()
@@ -5437,7 +5437,7 @@ mod tests {
             project
                 .read(cx)
                 .worktrees(cx)
-                .nth(0)
+                .next()
                 .unwrap()
                 .read(cx)
                 .as_local()
@@ -5486,7 +5486,7 @@ mod tests {
             project
                 .read(cx)
                 .worktrees(cx)
-                .nth(0)
+                .next()
                 .unwrap()
                 .read(cx)
                 .as_local()

crates/git_ui/src/project_diff.rs 🔗

@@ -280,7 +280,7 @@ impl ProjectDiff {
     fn button_states(&self, cx: &App) -> ButtonStates {
         let editor = self.editor.read(cx);
         let snapshot = self.multibuffer.read(cx).snapshot(cx);
-        let prev_next = snapshot.diff_hunks().skip(1).next().is_some();
+        let prev_next = snapshot.diff_hunks().nth(1).is_some();
         let mut selection = true;
 
         let mut ranges = editor

crates/language/src/proto.rs 🔗

@@ -86,7 +86,7 @@ pub fn serialize_operation(operation: &crate::Operation) -> proto::Operation {
                 proto::operation::UpdateCompletionTriggers {
                     replica_id: lamport_timestamp.replica_id as u32,
                     lamport_timestamp: lamport_timestamp.value,
-                    triggers: triggers.iter().cloned().collect(),
+                    triggers: triggers.clone(),
                     language_server_id: server_id.to_proto(),
                 },
             ),

crates/language_tools/src/key_context_view.rs 🔗

@@ -98,9 +98,7 @@ impl KeyContextView {
             cx.notify();
         });
         let sub2 = cx.observe_pending_input(window, |this, window, cx| {
-            this.pending_keystrokes = window
-                .pending_input_keystrokes()
-                .map(|k| k.iter().cloned().collect());
+            this.pending_keystrokes = window.pending_input_keystrokes().map(|k| k.to_vec());
             if this.pending_keystrokes.is_some() {
                 this.last_keystrokes.take();
             }

crates/settings_ui/src/keybindings.rs 🔗

@@ -472,13 +472,7 @@ impl KeymapEditor {
 
     fn current_keystroke_query(&self, cx: &App) -> Vec<Keystroke> {
         match self.search_mode {
-            SearchMode::KeyStroke { .. } => self
-                .keystroke_editor
-                .read(cx)
-                .keystrokes()
-                .iter()
-                .cloned()
-                .collect(),
+            SearchMode::KeyStroke { .. } => self.keystroke_editor.read(cx).keystrokes().to_vec(),
             SearchMode::Normal => Default::default(),
         }
     }

crates/title_bar/src/collab.rs 🔗

@@ -601,7 +601,7 @@ fn pick_default_screen(cx: &App) -> Task<anyhow::Result<Option<Rc<dyn ScreenCapt
                     .metadata()
                     .is_ok_and(|meta| meta.is_main.unwrap_or_default())
             })
-            .or_else(|| available_sources.iter().next())
+            .or_else(|| available_sources.first())
             .cloned())
     })
 }

crates/vim/src/normal.rs 🔗

@@ -221,7 +221,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
                 return;
             };
 
-            let anchors = last_change.iter().cloned().collect::<Vec<_>>();
+            let anchors = last_change.to_vec();
             let mut last_row = None;
             let ranges: Vec<_> = anchors
                 .iter()